开发者

NSTimer strange problem

开发者 https://www.devze.com 2023-01-24 16:55 出处:网络
I have 2 ViewController(RootViewController is UITabBarController, ViewController1 links to the item of UITabBarController)

I have 2 ViewController(RootViewController is UITabBarController, ViewController1 links to the item of UITabBarController)

in RootViewController

-(void)startTimer:(NSInteg开发者_StackOverflow社区er)v;
{
    [NSTimer scheduledTimerWithTimeInterval:10 
                                 target:self
                               selector:@selector(timerFired:)
                               userInfo:nil
                                repeats:YES]; 


}


- (void)timerFired:(NSTimer *)timer {


    [vViewController1 doSomething];
}

in ViewController1

-(void)doSomething;
{
   //I set breakpoint but never be fired
}

timerFired is activated but the function doSomething in ViewController1 never been fired.

Welcome any comment

Thanks

interdev


If you know for a fact that timerFired: is being called, then the only reason that doSomething won't get called is if vViewController1 is nill. Check that again.


The self in scheduledTimerWithTimeInterval target:self means RootViewController, so it will only invoke doSomething in RootViewController but not in ViewController1.

0

精彩评论

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

关注公众号