I have system "NavigationViewController -> MyViewController", and I programmatically want to present MyViewController inside a third view controller. The problem is that I don't have navigation bar in MyViewController after presenting it. Can you help me?
var VC1 = self.storyboard.instantiateViewControllerWithIdentifier("MyViewController") as ViewController
self.presentViewController(VC1, animated:true, completion: nil)
My navigation bar was not showing, so I have used the following method in Swift 2 iOS 9
SWIFT 3
I used an extension to UIViewController and a struct to make sure that my current view is presented from the favourites
1.Struct for a global Bool
2.UIVeiwController extension: presented modally as in the second option by "stefandouganhyde - Option 2 " and solving the back
Calling
presentViewController
presents the view controller modally, outside the existing navigation stack; it is not contained by your UINavigationController or any other. If you want your new view controller to have a navigation bar, you have two main options:Option 1. Push the new view controller onto your existing navigation stack, rather than presenting it modally:
Option 2. Embed your new view controller into a new navigation controller and present the new navigation controller modally:
Bear in mind that this option won't automatically include a "back" button. You'll have to build in a close mechanism yourself.
Which one is best for you is a human interface design question, but it's normally clear what makes the most sense.