Ios Swift-显示另一个视图控制器及其导航栏

Ios Swift-显示另一个视图控制器及其导航栏,ios,swift,viewcontroller,navigationbar,Ios,Swift,Viewcontroller,Navigationbar,我有两个视图控制器——一个带故事板,一个不带故事板。这两个视图控制器的顶部都有自己的导航栏。现在,当我使用self.presentViewController(editorViewController,动画:true,完成:nil)时,我的editorViewController会出现,但没有导航栏 有没有办法解决这个问题?试试self.navigationController!。pushViewController(…)我使用以下代码修复了该问题: let editorViewControll

我有两个视图控制器——一个带故事板,一个不带故事板。这两个视图控制器的顶部都有自己的导航栏。现在,当我使用
self.presentViewController(editorViewController,动画:true,完成:nil)时,
我的editorViewController会出现,但没有导航栏


有没有办法解决这个问题?

试试
self.navigationController!。pushViewController(…)
我使用以下代码修复了该问题:

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

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

因此,对于仍然好奇这个问题的每个人来说,考虑到我们已经有了现有的
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
self.present(destinationNavigationController, animated: true, completion: nil)
然后,我们要将
目标视图控制器
置于目标
UINavigationController
堆栈的顶部:

destinationNavigationController.pushViewController(destinationViewController, animated: true)
最后,仅显示目的地
UINavigationController

let destinationNavigationController = storyboard.instantiateViewController(withIdentifier: "DestinationNavigationController") as! UINavigationController
self.present(destinationNavigationController, animated: true, completion: nil)

Swift 5+

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

这里您的导航栏将替换为新的导航栏。

可能是因为您没有使用导航控制器。你能给我看一下你的故事板吗?这是我按“编辑”时的故事板。如果我坚持的话,图像编辑器编辑器视图控制器应该会弹出。。所以你的故事板只有视图控制器??我认为你应该使用NavigationController。看这里:Vasil,对于你刚才删除的问题,试着看看Toucan:但是呈现的UIViewController没有后退按钮。如何处理?@zulkarnainshah当你展示一个新的导航控制器时,你以前的导航堆栈会被移除。如果您需要显示后退按钮,则必须显示视图控制器,而不是导航控制器。