Scrolling an UITableView will stop Timer

I'm a beginner and I'm trying to write and application for iOS that will show to the user in the main screen a timer from 25 minutes to 0 (made of a UILabel whom text is updated every second using an NSTimer) and a UITableView (embedded in the UIViewController of the main screen) that will show a cell for each time the timer as reached the 0.

So in the main view controlled by my UIViewController I have: - UILabel: for the timer - UITableView: wich shows a cell for each time the timer as reached 0 - UIButton: to start the timer

Everything seems to work fine except for the fact that scrolling the UITableView will stop the timer from updating the label as long as the user keeps the finger on the tablewView. Can anyone tell me why the label won't change its text while the UITableView is being scrolled?

PS I think that this problem could be related to the fact that I'm not using threads since I've not learned to use them yet. I'm sorry if my english ain't perfect but I'm italian.


I did a quick Google search and the first result was this:

UILabel updating stops during scrolling UIScrollView

Seems to fit your needs exactly - as it's the exact same issue ;)


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

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)
链接地址: http://www.djcxy.com/p/75412.html

上一篇: 没有UITableViewController的UIRefreshControl

下一篇: 滚动UITableView将停止Timer