What I want to happen, in order: Alert box pops up saying processing (no buttons), the main processing function is called, when that completes the Alert box disappears, and then my navigation controller moves to the next view in the series.
What actually happens: The window freezes while the app processes, then the Alert box shows and disappears instantly while the navigation controller changes to the next view.
Best suggestion on how to fix this?
Code:
[_navigationController dismissModalViewControllerAnimated:NO]; //Camera dismisses
UIAlertView *alert;
alert = [[[UIAlertView alloc] initWithTitle:@"Analyzing\nPlease Wait..." message:nil delegate:nil cancelButtonTitle:nil otherButtonTitles: nil] autorelease];
[alert show];
[self processImage];
[alert dismissWithClickedButtonIndex:0 animated:YES];
[self gotoResults];
When calling
[alert show], the UI event is pushed into main run loop. You can process other tasks in another function. For example, a function namedfooprocesses other tasks. And after calling[alert show], we call[self performSelector:@selector(foo) withObject:nil afterDelay:0.1]to invokefoo. That will give run loop some time to handle the showing event of alert view.Edit:
You can read about -performSelector:withObject:afterDelay: in this apple official document. You can assign 0.0 as parameter for afterDelay, and the document said: