Reputation: 877
I have a problem with my nav bar in Swift. I move from one view controller to another like this:
let storyBoard : UIStoryboard = UIStoryboard(name: "Main", bundle:nil)
let nextViewController = storyBoard.instantiateViewControllerWithIdentifier("GameViewController") as GameViewController
nextViewController.transitioningDelegate = self.transitionManager
self.presentViewController(nextViewController, animated:true, completion:nil)
But when I see my second view controller, it disappears. I can't use a segue here.
How do I add a navigation bar, with a bar button item, without a Navigation controller in Swift?
I saw this: Add a navigation bar to a view without a navigation controller
Upvotes: 1
Views: 3133
Reputation: 22969
To do this you can use IB: drag a Navigation Bar
from the left pane onto your UIViewController
. As shown in the picture:
To make the Navigation Bar
size correctly depending on the device, you need to add constraints to pin the top edge to the top of the view and both the left and right edges to the left and right of the view (the height is intrinsic and doesn't need a constraint). This can also be done in IB:
Once you've done these two steps you can use the Navigation Bar
just like you would normally - for example I've added a Bar Button Item
to the Navigation Bar
in the first image.
Upvotes: 4