Is there a way to stop a UIViewController from being popped from a UINavigationController's stack wh

Posted by yabada on Stack Overflow See other posts from Stack Overflow or by yabada
Published on 2010-04-23T22:23:51Z Indexed on 2010/04/23 23:03 UTC
Read the original article Hit count: 289

I have a UINavigationController with a root view controller and then I push a UIViewController onto the navigation controller's stack. When the user taps the backBarButtonItem I'd like to be able to have an alert view pop up if there are certain conditions met and cancel the pop of the view controller. For example, the user can make certain selections but some combination of them may be invalid so I want to notify them to make changes.

I know that I can prevent the user from making an invalid combination or have an alert view pop up when the invalid combination is selected but I'd rather not do that. The user may be changing selections and may be aware that a certain combination is invalid but I'd rather let them select something that makes the combination invalid then go change something else (and notify them if they haven't made changes before trying to go to the previous screen). For example, if I prevent them from make the invalid combination then they may have to scroll up on a screen, change something, then scroll back down instead of making a selection then scrolling up and changing something.

Using viewWillDisappear: doesn't work because, although I can produce an alert view, I cannot figure out a way to prevent the pop from occurring. The alert view pops up but the view controller still pops and they are back to the root view controller (with the alert view displaying).

Is there a way to prevent the pop from occurring? If not, is this something worth filing a bug report about or is this unnecessary and/or esoteric?

© Stack Overflow or respective owner

Related posts about cocoa-touch

Related posts about iphone