title: How to create a confirmation Pop Up when pushing Back button in iOS?
body: <p>I want to add a pop up when someone pushes the "Back" button of my iOS App, to ask the user if he really wants to come back. Then, depending on the user's response, I would like to undo the action or proceed. I've tried to add the code in the viewWillDisappear function of my view and then write the proper delegate but it doesn't work, because it always change the view and then show the pop up. My code is:</p>
  
  <pre><code>    -(void) viewWillDisappear:(BOOL)animated {
         _animated = animated;
         if ([self.navigationController.viewControllers indexOfObject:self]==NSNotFound) {
             UIAlertView *alert_undo = [[UIAlertView alloc] initWithTitle:@"UIAlertView"
                                                                  message:@"You could be    loosing information with this action. Do you want to proceed?"
                                                                 delegate:self
                                                        cancelButtonTitle:@"Go back"
                                                        otherButtonTitles:@"Yes", nil];
             [alert_undo show];
         }
         else [super viewWillDisappear:animated];
     }
  </code></pre>
  
  <p>And the delegate implementation is: </p>
  
  <pre><code>- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
  {
      NSString *title = [alertView buttonTitleAtIndex:buttonIndex];
      if([title isEqualToString:@"Yes"])
      {
          [super viewWillDisappear:_animated];
      }
  }
  </code></pre>
  
  <p>This is not working at all. Does anybody now a better way to do it or what could be wrong?</p>
  
  <p>Thank you very much, </p>