I have a tab bar application with three tabs. In my second tab view i have a UIProgressView. I have a NSTimer in my viewDidLoad method which calls a method which updates the progressView
progressTimer = [NSTimer scheduledTimerWithTimeInterval:1.5 target:self selector:@selector(updateProgress) userInfo:nil repeats:YES];
All is fine so far.
I want to know how do i run the timer in the background throughout the lifecycle of the app, so that progressView is updated no matter which view the user is in. It will be great if you can show me with a code snippet.
Thanks in advance.
It’s not advisable to update UI elements from background threads. Also, it’s not advisable to modify UI elements of a view when the user is not in that view. You are using precious system resources.
Better way is to update the ProgressBar as soon as that view becomes active…
UPDATE: You can see here to know how to run a task in background thread. You could set up your
NSTimerto start in the selector you specify there. But again, this kind of stuff could lead to some weird bugs. Better to avoid..