滚动UITableView将停止计时器

Big*_*Lex 8 iphone xcode objective-c ios

我是初学者,我正在尝试编写和应用iOS,它将在主屏幕上向用户显示一个从25分钟到0的定时器(由UILabel每隔一秒更新一个文本组成NSTimer)和一个UITableView(嵌入式)在UIViewController主屏幕中),每次定时器到达0时将显示一个单元格.

所以在我控制的主视图中UIViewController我有: - UILabel:对于定时器 - UITableView:每次定时器达到0时显示一个单元格 - UIButton:启动定时器

一切似乎工作得很好,除了滚动UITableView意志停止计时器更新标签,只要用户将手指放在tablewView上.谁能告诉我为什么标签UITableView在滚动时不会改变文字?

PS我认为这个问题可能与我没有使用线程的事实有关,因为我还没有学会使用它们.

Yog*_*ate 6

Swift 3.x中的解决方案:

self.updateTimer = Timer.scheduledTimer(timeInterval:1.0, target: self, selector: "updateFunction", userInfo: nil, repeats: true)
RunLoop.current.add(self.updateTimer, forMode: RunLoopMode.commonModes)
Run Code Online (Sandbox Code Playgroud)


VvD*_*PzZ 5

updateTimer = [NSTimer scheduledTimerWithTimeInterval:.01 target:self selector:@selector(updateCurrentTime) userInfo:p repeats:YES];
[[NSRunLoop currentRunLoop] addTimer:updateTimer forMode:NSRunLoopCommonModes];
Run Code Online (Sandbox Code Playgroud)


ric*_*ter 4

计时器在跟踪运行循环模式期间不会触发,这就是您在滚动时所处的模式。有关详细信息,请查看有关运行循环模式的 NSTimer 文档,或有关滚动视图的 WWDC 2012 会议。