Search code examples
swiftxcodeuinavigationbarsegueuistoryboardsegue

How to present view controller modally while keeping navigation bar present. (For a settings view controller)


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!


Solution

  • 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)