Christopher Francisco
Christopher Francisco

Reputation: 16278

iOS dismissing a modally presented Navigation Controller

I present a Navigation Controller this way:

let navController = self.storyboard?.instantiateViewControllerWithIdentifier("myId") as! UINavigationController

self.presentViewController(navController, animated: true, completion: nil)

How do I dismiss this Navigation Controller using a Navigation Bar Button that is set up from the storyboard? is it possible?

NOTE: I'm not asking the logic of how to dismiss a VC, I am aware of the protocol/delegate pattern. Instead I'm asking whether I can put a "Cancel" button in the nav bar, and if that button's IBAction would be declared inside Navigation Controller subclass or in the navcontroller's root view controller

Upvotes: 0

Views: 690

Answers (1)

sixthcent
sixthcent

Reputation: 1160

UINavigationController does not own the navigation bar button items. Its provided by the view controller pushed in to the stack. You can dismiss the UINavigationController from any of the view controller's navigation bar, provided it was presented modally. It is possible to add a UINavigationBar in storyboard and have an IBOutlet for bar button item that performs dismissal.

Upvotes: 1

Related Questions