可能的重复:
NSTimer 不会停止 https://stackoverflow.com/questions/1031554/nstimer-doesnt-stop
我有这个代码:
[NSTimer scheduledTimerWithTimeInterval:110.0
target:self
selector:@selector(targetMethod:)
userInfo:nil
repeats:YES];
- (void) targetMethod:(NSTimer) timer{
NSLog(@"Hello World");}
在 targetMethod 中,我可以使用 [timer invalidate] 停止计时器,但是在这个方法之外,我怎样才能停止 targetMethod?
你可以保留你的NSTimer
在变量中并使用停止计时器invalidate
方法。就像下面这样:
NSTimer * myTimer = [NSTimer scheduledTimerWithTimeInterval:110.0
target:self
selector:@selector(targetMethod:)
userInfo:nil
repeats:YES];
[myTimer invalidate];
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)