(People might think that I'm late for years answering this question, but it might help someone else)
I assume that your problem lies in where, when the view controller appears, you display the warning view and at the same time try to translate the user back into the view. I would recommend you follow a hierarchical approach here:
First of all, declare your warning as a global object, i.e.
@property(nonatomic,retain) UIAlertView *sampleAlert;
Now write your warning display code wherever it appears, say, for example:
-(IBAction)buttonClicked:(id)sender { self.sampleAlert = [[UIAlertView alloc] initWithTitle:@"test" message:@"test" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil]; [sampleAlert show]; [sampleAlert release]; }
Finally, try switching to the desired user when the "Ok" button is pressed, i.e. you need to use the alertView didDismissWithButtonIndex method, i.e.
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex { if(alertView == sampleAlert) { [self.navigationController popViewControllerAnimated:YES]; } }
Please note that if you have a warning with several buttons, you also need to check the button index for distinctive actions, i.e. check with
if(alertView == sampleAlert && buttonIndex == 0) { //Do your stuff } else { //Do something else }
This will definitely avoid the application crash, thanks :)