iPhone: How do I override the back button in a Navigation Controller?

Posted by Angelo Stracquatanio on Stack Overflow See other posts from Stack Overflow or by Angelo Stracquatanio
Published on 2011-01-07T20:49:19Z Indexed on 2011/01/07 20:54 UTC
Read the original article Hit count: 214

Hello,

In my app I have a basic Navigation Controller. For all of my views, except one, the controller works as it should.

However, for one view in particular, I would like the 'back' button to not go back to the previous view, but to go to one I set. In particular it is going to go back 2 views and skip over one.

After doing some research I found that I can intercept the view when it disappears, so I tried to put in code to have it navigate to the page I would like:

- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
//i set a flag to know that the back button was pressed
if (viewPushed) {
    viewPushed = NO;   
} else {
    // Here, you know that back button was pressed
    mainMenu *mainViewController = [[mainMenu alloc] initWithNibName:@"mainMenu" bundle:nil];
    [self.navigationController pushViewController:mainViewController animated:YES];
    [mainViewController release];
}   

}

That didn't work, so does anyone have any ideas?

Thanks!!

© Stack Overflow or respective owner

Related posts about iphone

Related posts about objective-c