【问题标题】:NSTimer not repeating from AppDelegateNSTimer 不从 AppDelegate 重复
【发布时间】:2012-05-11 14:37:10
【问题描述】:

为什么在 appDidFinishLaunching 中不会重复?

self.ti = [NSTimer timerWithTimeInterval:10. target:self selector:@selector(bounce:) userInfo:nil repeats:YES];
[self.ti fire];

非常感谢

朱尔斯

【问题讨论】:

  • 'bounce' 中的代码是什么?另外,你是如何设置“ti”的。
  • 在反弹中,我现在只是在登录以查看它是否被调用,ti 是我的标题中的一个属性(强,非原子)并合成。看来代码甚至没有触发一次,更不用说重复了?再次感谢

标签: iphone ios nstimer


【解决方案1】:

我认为您的bounce 签名错误。应该是

- (void)bounce:(NSTimer*)theTimer {
    NSLog(@"Here...");
}

您应该使用selector(bounce:) 来安排此方法。您还应该调用scheduledTimerWithTimeInterval 而不是timerWithTimeInterval

self.ti = [NSTimer
    scheduledTimerWithTimeInterval:10.
                            target:self
                          selector:@selector(bounce:)
                          userInfo:nil
                           repeats:YES];

【讨论】:

    【解决方案2】:

    我不确定它是否会有所帮助,但请尝试使用scheduledTimerWithTimeInterval 方法。一个例子:

    self.ti = [NSTimer scheduledTimerWithTimeInterval:10. target:self selector:@selector(bounce) userInfo:nil repeats:YES];
    

    希望对你有帮助

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-01-13
      • 2013-05-08
      • 2018-09-26
      • 2023-03-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多