简体   繁体   English

无效-iOS 6不会停止计时器

[英]invalidate - ios 6 does not stop the timer

I have a timer declared like so: 我有一个这样声明的计时器:

 @property (nonatomic,strong) NSTimer* tutorialTimer;
 ...
 self.tutorialTimer = [NSTimer scheduledTimerWithTimeInterval:3 target:self selector:@selector(showTutorial) userInfo:nil repeats:YES];

when clicking on a button I'm stopping the timer(or at least wish to stop) like so: 当单击按钮时,我正在停止计时器(或至少希望停止),如下所示:

[self.tutorialTimer invalidate];
self.tutorialTimer = nil;

the timer keeps invoking...suggestions? 计时器不断调用...建议?

NSTimer should work in main Thread . NSTimer应该在主线程中工作。 you can check the process use code 您可以检查流程使用代码

 if ([NSThread isMainThread])
{
   [self.tutorialTimer invalidate];
   self.tutorialTimer = nil;
}

to find out whether if it can step into [self.tutorialTimer invalidate]; 找出是否可以进入[self.tutorialTimer invalidate];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM