Swift - 使用其导航栏呈现另一个视图控制器

Vas*_*nev 8 viewcontroller navigationbar ios swift

我有两个ViewControllers - 一个有故事板,一个没有.这两个视图控制器都在顶部有自己的导航栏.现在当我使用self.presentViewController(editorViewController, animated: true, completion: nil)我的editorViewController时出现但没有它的导航栏.

任何想法如何解决这一问题?

Vas*_*nev 22

我使用以下代码修复了问题:

let editorViewController = IMGLYMainEditorViewController()
let navEditorViewController: UINavigationController = UINavigationController(rootViewController: editorViewController)
self.presentViewController(navEditorViewController, animated: true, completion: nil)
Run Code Online (Sandbox Code Playgroud)

我刚刚添加了navEditorViewController它,因为它使我的导航栏显示其项目.


Dav*_*d P 9

尝试 self.navigationController!.pushViewController(...)


Wim*_*sha 5

斯威夫特 5+

let destinationNavigationController = self.storyboard!.instantiateViewController(withIdentifier: "nav") as! UINavigationController
destinationNavigationController.modalPresentationStyle = .fullScreen        
self.present(destinationNavigationController, animated: true, completion: nil)
Run Code Online (Sandbox Code Playgroud)

此处您的导航栏将替换为新的导航栏。