【问题标题】:NSTimer not callingNSTimer 没有调用
【发布时间】: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”的代码?
  • 是的,它被执行了。通过调试器检查它。

标签: iphone nstimer


【解决方案1】:

通过查看您的代码。它必须工作。做几个试验:

  1. 检查您的第三个按钮点击事件是否被调用。

  2. 检查你是否在其他地方做timer=nil , [timer invalidate];

【讨论】:

  • 我找到了解决方案。我从其他地方使计时器无效。感谢您的回复。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-05-18
  • 1970-01-01
  • 2012-07-15
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多