Iphone NSTimer不打电话

Iphone NSTimer不打电话,iphone,nstimer,Iphone,Nstimer,我对此进行了大量的研究,找到了许多解决方案,但没有人能解决我的问题 我正在使用一个NSTimer,并通过一个按钮将其激活。单击此处,工作正常。现在,我在第二次按钮点击时使计时器无效,在第三次按钮点击时再次启动计时器,但在第三次按钮点击时,我的计时器不工作。谁能告诉我我怎么了 我正在使用的代码 按钮1单击: timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(updateCo

我对此进行了大量的研究,找到了许多解决方案,但没有人能解决我的问题

我正在使用一个NSTimer,并通过一个按钮将其激活。单击此处,工作正常。现在,我在第二次按钮点击时使计时器无效,在第三次按钮点击时再次启动计时器,但在第三次按钮点击时,我的计时器不工作。谁能告诉我我怎么了

我正在使用的代码

按钮1单击:

timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self      selector:@selector(updateCountdown) userInfo:nil repeats:YES];
按钮2单击:

    if (timer != nil && [timer isValid])
    {
     [timer invalidate];
     timer=nil;
    }
按钮3单击:

 timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self      selector:@selector(updateCountdown) userInfo:nil repeats:YES];

现在点击按钮3定时器不工作。

查看您的代码。它必须起作用。进行两次试验:

  • 检查是否正在调用您的第三个按钮单击事件

  • 检查您是否正在执行
    timer=nil,[timer invalidate]其他地方


  • 您已经通过调试日志或使用调试器确认“button3 click”的代码已实际执行?是,已执行。通过调试器检查,我找到了解决方案。我在其他地方使计时器失效。谢谢你的回复。