Dmitry Minkovsky
Dmitry Minkovsky

Reputation: 38193

UINavigationItem on destination scene disappears when segue style changed from Push to Modal

With a seque between UINavigationController scenes, why does changing a seque style from Push to Modal cause the UINavigationItem on the destination scene to disappear from the IB and the built app? Interestingly, the UINavigationItem is still in the IB hierarchy.

How do I get a Modal seque with the UINNavigationItem still visible on the destination scene? I'm trying to do something simple-seeming like the edit functionality in the iPhone Contacts app. There you have a Modal that comes up on contact edit, and you can navigate back to a contact detail when finished.

Upvotes: 1

Views: 270

Answers (2)

rickster
rickster

Reputation: 126167

Any view controller can have a navigation item, but it only shows up if your view controller is embedded in a navigation controller. Modal view controllers don't inherit the navigation controllers of the view controller that presented them -- essentially, they represent a branch in your user's path through the app, rather than an extension of the navigation stack they came from.

If you want the stuff a navigation controller provides in your modal view controller, embed that VC in a navigation controller, and present that navigation controller modally.

(Or if you just want a navigation bar to appear at the top of the view, and don't care about the other stuff you get from UINavigationController, you can drop a UINavigationBar (Navigation Bar in the Object Library) into the view in IB.)

Upvotes: 1

rdelmar
rdelmar

Reputation: 104092

If you're presenting a modal view controller, it won't have the navigation bar that was present in the presenting controller (assuming that one is embedded in a navigation controller). The top bar in the Contacts app is probably a UIToolbar ("Toolbar" in the Objects Library). You can drag one of those into your controller, and add bar button items to it in IB. There are a lot of different styles for these buttons that you can choose from, including "Done" and "Cancel".

Upvotes: 1

Related Questions