I want to start a calculation task that will last for a couple of minutes. Since the solution is getting closer and closer to the optimal solution with time, I want to give the user a button to stop the calculation at any time and stick with the approximation.
But when I start my calculation in viewDidLoad the view with the stop button isn’t even presented to the user until the calculation ends. So I need some kind of background calculation process – but how can I do this on iOS 5?
I also want to be able to update a progress bar in my view (with the stop button).
Here’s my code in the UIViewController subclass:
- (void)viewDidLoad
{
[super viewDidLoad];
// doing some initialization
[self startCalculation]; // do this in background for stopping capabilities?
}
- (void)startCalculation {
// start calculation and update progress bar every 200 ms or so
}
Could somebody please help me?
General answer is to call
startCalculationfrom within anNSThreadThen to stop it
If you want to update a progress view from within this thread make sure to call the progress updates from the ui main thread like so