Dear iPhone Developers,
I am writing a Navigation based iPhone application. I want to execute a piece of code but before the execution I want the viewController to pop up. The method that I want to implement looks as follows;
- (IBAction)executeTheCode {
// set a BOOLEAN so that the user can not repeat the same action
// unless the previous run is complete.
isRunning = TRUE;
[self.navigationController popViewControllerAnimated:YES];
// The piece of Code goes here
//
}
the code, that is being executed, is iterative and would take some time. I want the application to pop up immediately so that the user can interact with the rest of the stuff meanwhile. In the above case I just put a do loop to check if it works but it does not pop up unless the do loop is complete. Even the back button does not work while the do loop is being executed. Is there any way (if possible at all) to do that? Thanks.
popViewControllerAnimated
Does the opposite of what you want to do. Pop removes the top view controller from the stack.
What you want is (void)viewDidAppear or (void)viewWillAppear method….
In this method you can kick off a progress indicator or do what ever you want to do. For example overlay a waiting UIView while your program is calculating.
What I think you want to do is kick off a thread in one of the above methods that does the work in a background thread.
Check
[self performSelectorInBackground:@selector(setup:) withObject:nil];
in the documentation. This will run the method setup in your project in the background, allowing the user to work with the rest of your UIView while -(void)setup runs in the background.