开发者

daisy chain function calls (method 1 calls method 2, method 2 calls method 3)

开发者 https://www.devze.com 2023-03-25 00:23 出处:网络
I have a function that calls another function. i want the second function to call a third function. they all then return to the first function and finish the code;

I have a function that calls another function. i want the second function to call a third function. they all then return to the first function and finish the code;

-(void) select
{
  //do code
  [self drawMap];
}

-(voi开发者_开发问答d) drawMap
{
  //do code
  [self performSelector:@selector(showActionSheet) withObject:nil afterDelay:2];
}

-(void) showActionSheet
{
  //do code
}

But the showActionSheet function is not being called, its not firing.

EDIT: but if i change

[self performSelector:@selector(showActionSheet) withObject:nil afterDelay:2]; 

to

[self showActionSheet];

it works fine. but i want to delay the showing of an action sheet a few seconds so the user can see the changes to the map.


I believe you need to add an id parameter to your showActionSheet method in order for theperformSelector:withObject:afterDelay method to work correctly.

Try changing the signature of your method to:

-(void) showActionSheet:(id) obj { ... }

And as @MByD added, you need to add a colon to your selector:

[self performSelector:@selector(showActionSheet:) withObject:nil afterDelay:2]; 


Are you doing this in a thread that does not have a NSRunLopp, because it is the NSRunLoop that not only responsible for handling inputs but it is also responsible for performing timed actions.

Also is it possible that you NSRunLoop is not give a chance to wait for input and fire timed events, if you have some code that is running for a long time before returning back to your NSRunLoop then your NSRunLoop will not get a change to do anything until then.

Another possibility is if you have set up you NSRunLoop in an odd way you may have to use

- [NSObject performSelector:(SEL)aSelector
                 withObject:(id)anArgument
                 afterDelay:(NSTimeInterval)delay
                    inModes:(NSArray *)modes];

instead and try a different mode other than row default one (NSDefaultRunLoopMode).

0

精彩评论

暂无评论...
验证码 换一张
取 消