Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UITableView stops updating content while scrolling through view?

I have a UITableView with which works fine and updates fine. I also have a timer that updates each UITableView label and a progress view, when the user is scrolling the table view it stops updating/refreshing the content (labels and progress view) in the UITableView until they are done scrolling.

In addition to the content not updating I have found that when the user is scrolling the entire app hangs. I have two timers and I put print statement in both, but neither prints when the user is scrolling. I have not been able to find a swift or swift 2 solution to this.

like image 662
Corey Smith Avatar asked Feb 06 '23 22:02

Corey Smith


1 Answers

This is completely unrelated to Swift whatsoever.

You probably scheduled the NSTimer using the default method, which results in adding it to a runloop in a way that it's not triggered while scrolling. You need to add it to the main runloop with a NSRunLoopCommonModes mode instead.

E.g.

let timer = NSTimer(timeInterval: 1.0, target: self, selector: #selector(update), userInfo: nil, repeats: false)
NSRunloop.mainRunLoop().addTimer(timer, forMode: NSRunloopCommonModes)
like image 178
macbirdie Avatar answered Feb 09 '23 10:02

macbirdie