I downloaded some code from http://github.com/matej/MBProgressHUD to show a progress meter when doing something.
This is the code that makes the progress meter pop up.
[HUD showWhileExecuting:@selector(myTask) onTarget:self withObject:nil animated:YES];
This will show a progress meter while the method myTask is running.
The strange thing is that it will also allow program execution to continue below this line while myTask is running. This is not the behavior I want. I want the progress meter to show while myTask is running, and only after myTask finishes running do I want program execution to continue below this line.
This is the code for the showWhileExecuting method.
- (void)showWhileExecuting:(SEL)method onTarget:(id)target withObject:(id)object animated:(BOOL)animated {
methodForExecution = method;
targetForExecution = [target retain];
objectForExecution = [object retain];
// Launch execution in new thread
taskInProgress = YES;
[NSThread detachNewThreadSelector:@selector(launchExecution) toTarget:self withObject:nil];
// Show HUD view
[self show:animated];
}
In order to get the behavior I want, should I edit this code, or do something else?
I tried to get around this problem by setting a bool value before calling this method which causes program execution to be stuck in a while loop immediately after until the bool value is changed at the end of myTask. This works, but for some reason it causes the meter to only show up for an instant at the end, and not throughout like it's supposed to. Why is that?