【问题标题】:NSTimer and UITabBarNSTimer 和 UITabBar
【发布时间】:2012-07-06 09:31:15
【问题描述】:

我在一个视图中有三个标签栏项目。在第一个选项卡项中的开始按钮操作上有一个 NSTimer 计划。当我按下另一个选项卡项并进入最近的选项卡项(即带有 NSTimer 的选项卡项)时,它会将秒数增加 2。如果我第二次这样做它将秒增加 3 等等。我希望秒增加 1。

这是我用来安排 NSTimer 的代码

timer = [NSTimer scheduledTimerWithTimeInterval:1.0f target:self selector:@selector(timerTick:) userInfo:nil repeats:YES];
[[NSRunLoop currentRunLoop] addTimer:timer forMode:NSDefaultRunLoopMode];

我尝试使用 [timer invalidate] 解决它;但它没有给我一个正确的结果。

提前致谢。

【问题讨论】:

  • 你能解释一下吗?我不太明白。
  • 我认为他的意思是计时器变得快 2 倍和 3 倍。
  • 他每次都想增加?

标签: iphone nstimer uitabbar


【解决方案1】:

- (void)viewWillAppear:(BOOL)animated 方法中通过[timer invalidate]; 使计时器无效

然后再次启动它:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-24
    相关资源
    最近更新 更多