0
的同一个实例我想要做的事与我的NSTimer当我离开我的控制器,让我不viewDidDisappear如何杀死的NSTimer
无效的NSTimerself.timer = [NSTimer scheduledTimerWithTimeInterval:1
target:self
selector:@selector(stopWatch)
userInfo:nil
repeats:YES];
- (void)stopWatch
{
// Do something
NSLog(@"stopWatch");
}
-(void)viewDidDisappear:(BOOL)animated {
// Do not invalidate NSTimer here;
}
退出该控制器后,我回来这控制器和
- (void)viewDidLoad
{
[self.timer invalidate];
self.timer = nil;
self.timer = [NSTimer scheduledTimerWithTimeInterval:1
target:self
selector:@selector(stopWatch)
userInfo:nil
repeats:YES] ;
}
所以我有2个的NSTimer运行的同时
我怎样才能失效我以前的NSTimer当我做一个新的?
问候
我不明白;你怎么能有两个计时器,当你使无效的旧计时器? – trojanfoe
,因为0.5秒后,我的“秒表”功能被称为 –
目前尚不清楚你想要什么。为什么当视图消失时你想让定时器激活?为什么要启动一个新的计时器,如果你已经有一个运行?计时器的某些指示会有所帮助。 – trojanfoe