Here is an example of what I'm talking about: https://media.giphy.com/media/3o6nUPLqKrMN64tdNm/giphy.gif Many apps do this. The contacts app when you add a new contact, etc. When I try to present my settings page modally, however, the navigation bar disappears. Any idea how to get around this? Thanks in advance!
Asked
Active
Viewed 5,084 times
2
-
1Create a navigation controller with root view controller as your view controller and then present navigation controller. – Bilal Nov 03 '17 at 16:44
-
1Present navigation controller instead. It's just works – Mannopson Nov 03 '17 at 16:45
-
1Trivially simple. This is an independent navigation controller, merely so that there can be a place for the done button. It has its own navigation bar — nothing to do with your existing navigation controller and navigation bar. – matt Nov 03 '17 at 16:49
1 Answers
5
Create a navigation controller with root view controller as your view controller and then present navigation controller. Something like this.
let vc = // your view controller
let nav = UINavigationController(rootViewController: vc)
self.present(nav, animated: true, completion: nil)

Bilal
- 18,478
- 8
- 57
- 72
-
Thanks! How do I access the variables in the 2nd view controller from the first view controller? – Jack Gruber Nov 03 '17 at 17:08
-
@JackGruber Use the segues. Make your Navigation controller as a destination controller. And make your embedded vc as a `topViewController` of `UINavigationController`. – Mannopson Nov 03 '17 at 17:11
-
thanks! One more question, how would I access the 2nd navigation controller from the rootview controller. If I were to do self.navigationController!.viewControllers[0], it would only be using my original navigation controller. – Jack Gruber Nov 03 '17 at 17:30
-
-
Would calling `self.dismiss(animated: true, completion: nil)` be the correct way to dismiss the vc programmatically then? – Eric33187 Apr 15 '21 at 01:24
-
-
Add `nav.modalPresentationStyle = .fullScreen` if you want a full screen presentation – Channel May 11 '21 at 07:35