IOS:停止NSTimer [英] IOS: stop a NSTimer
本文介绍了IOS:停止NSTimer的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
可能重复:
NSTimer不会停止
我有这段代码:
[NSTimer scheduledTimerWithTimeInterval:110.0
target:self
selector:@selector(targetMethod:)
userInfo:nil
repeats:YES];
- (void) targetMethod:(NSTimer) timer{
NSLog(@"Hello World");}
在targetMethod我可以用[timer invalidate]停止计时器,但是在这个方法之外,我怎么能停止targetMethod?
in targetMethod I can stop timer with [timer invalidate], but out of this method, How can I stop targetMethod?
推荐答案
您可以在变量中保留 NSTimer
并使用无效$ c $停止计时器c>方法。如下所示:
You can keep your NSTimer
in a variable and stop the timer using the invalidate
method. Like the following:
NSTimer * myTimer = [NSTimer scheduledTimerWithTimeInterval:110.0
target:self
selector:@selector(targetMethod:)
userInfo:nil
repeats:YES];
[myTimer invalidate];
这篇关于IOS:停止NSTimer的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文