【发布时间】:2013-08-11 01:51:50
【问题描述】:
我对此进行了很多搜索并找到了很多解决方案,但没有一个适合我的情况。
我正在使用 NSTimer 并通过一个按钮激活它点击这里它工作正常。现在我在第二个按钮单击时使计时器无效,并在第三个按钮单击时再次启动它,但在第三个按钮单击时我的计时器不起作用。谁能告诉我是怎么回事。
我正在使用的代码。
button1 点击:
timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(updateCountdown) userInfo:nil repeats:YES];
button2 点击:
if (timer != nil && [timer isValid])
{
[timer invalidate];
timer=nil;
}
button3 点击:
timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(updateCountdown) userInfo:nil repeats:YES];
现在点击 button3 计时器不起作用。
【问题讨论】:
-
您已经通过调试日志或使用调试器确认实际执行了“button3 click”的代码?
-
是的,它被执行了。通过调试器检查它。