Swift - present another view controller with a navigation bar

I have two ViewControllers - one with a storyboard and one without. Both of these view controllers have their own navigation bar at the top. Now when I use self.presentViewController(editorViewController, animated: true, completion: nil) , my self.presentViewController(editorViewController, animated: true, completion: nil) editor appears, but without its navigation bar.

Any ideas how to fix this?

+5
source share
3 answers

I fixed the problem using the following code:

 let editorViewController = IMGLYMainEditorViewController() let navEditorViewController: UINavigationController = UINavigationController(rootViewController: editorViewController) self.presentViewController(navEditorViewController, animated: true, completion: nil) 

I just added navEditorViewController since it created my navigation bar with its elements.

+12
source

Try self.navigationController!.pushViewController(...)

+6
source

So, for everyone, this problem is still of interest, given that we already have a UINavigationController except current :

Swift 3

First we need to find the UIViewController that we want to introduce:

 let storyboard = UIStoryboard(name: "Main", bundle: nil) let destinationViewController = storyboard.instantiateViewController(withIdentifier: "DestinationViewController") as! DestinationViewController 

Next, we do the same for the UINavigationController :

 let destinationNavigationController = storyboard.instantiateViewController(withIdentifier: "DestinationNavigationController") as! UINavigationController 

Then we want to bring the DestinationViewController to the top of our destination UINavigationController :

 destinationNavigationController.pushViewController(destinationViewController, animated: true) 

Finally, only the current destination of the UINavigationController :

 self.present(destinationNavigationController, animated: true, completion: nil) 
+1
source

Source: https://habr.com/ru/post/1245555/


All Articles