I have a progress indicator in a tableview cell that does not update its progress while the user interacts with the tableview. When the interaction stops the indicator jumps to where it should be.
How can this be avoided so that the animations continue even if the user is scrolling the tableview?
Can they be added to a runloop? If both the interaction and the animating needs to happen on the main thread, what work around can be done?
First, you should make sure you really do want those progress indicators to update – The default behavior with
UIScrollViewtype classes when scrolling is to pause any UI updates within them to keep things responsive. I’ve found things like scrolling speed can degrade surprisingly quickly whenever I try to do anything extra, especially on older devices.Warnings aside, how do we do this? Well it looks like this question has a solution for you. A brief summary is:
NSTimertrigger your progress indicator updates, run that timer inNSRunLoopCommonModesso it will still fire while scrolling.That’s it.
UIViewupdating is not the issue while scrolling, running the code that triggers the update is. By using a timer that is ‘scroll-proof’, your indicators should update just fine. There is some good example code at the linked question, so do click through to read!