我有两个ViewControllers - 一个带有故事板,一个没有。这两个视图控制器都在顶部有自己的导航栏。现在,当我使用self.presentViewController(editorViewController, animated: true, completion: nil)
时,我的editorViewController出现但没有导航栏。
任何想法如何解决这个问题?
答案 0 :(得分:19)
我使用以下代码解决了问题:
let editorViewController = IMGLYMainEditorViewController()
let navEditorViewController: UINavigationController = UINavigationController(rootViewController: editorViewController)
self.presentViewController(navEditorViewController, animated: true, completion: nil)
我刚刚添加了navEditorViewController
,因为它使我的导航栏显示了其项目。
答案 1 :(得分:8)
尝试"id" => 32,"numero" => 469
答案 2 :(得分:2)
因此,对于仍然对此问题感到好奇的人,鉴于我们已经存在除当前之外的 UINavigationController
:
Swift 3
首先,我们需要找到我们想要呈现的 UIViewController
:
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let destinationViewController = storyboard.instantiateViewController(withIdentifier: "DestinationViewController") as! DestinationViewController
接下来,我们为 UINavigationController
做同样的事情:
let destinationNavigationController = storyboard.instantiateViewController(withIdentifier: "DestinationNavigationController") as! UINavigationController
然后,我们希望将 DestinationViewController
置于目标 UINavigationController
堆栈的顶部:
destinationNavigationController.pushViewController(destinationViewController, animated: true)
最后,只显示目的地 UINavigationController
:
self.present(destinationNavigationController, animated: true, completion: nil)
答案 3 :(得分:1)
Swift 5 +
let destinationNavigationController = self.storyboard!.instantiateViewController(withIdentifier: "nav") as! UINavigationController
destinationNavigationController.modalPresentationStyle = .fullScreen
self.present(destinationNavigationController, animated: true, completion: nil)
在这里,您的导航栏将替换为新的导航栏。