I have a standard UIViewController which works a charm. However, I want to add a UINavigationController on top of this as a subview, add and remove it at will. However, it seems you can’t simply add another controller onto a current controller as a subview. So how do I go about this?
Thanks.
Here’s some code that creates a new view in a navigation controller and shows it “on top” (presents it modally).
There’s a few key things here:
If you present a nav controller modally, you need to set it’s left & right buttons (if you need to) before you initWithRootController and presentModally
Even if you’re current view is in a navController, if you present it modally, it needs to be wrapped in a UINavigationcontroller (there’s some SO posts covering that)
UINavigationController with presentModalViewController
Then, from within the view you just presented modally, you can dismiss it. For example, in this code the save and cancel buttons added above are associated with these IBAction methods on the view controller you presentedModally: