Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scrolling an UITableView will stop Timer [duplicate]

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?

P.S. 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.

like image 913
BigLex Avatar asked Aug 27 '12 15:08

BigLex


1 Answers

Solution in 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)
like image 179
yo2bh Avatar answered Sep 30 '22 11:09

yo2bh