导航控制器不能正常工作

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了导航控制器不能正常工作相关的知识,希望对你有一定的参考价值。

在过去的两个月里,我一直在使用下面的代码快速访问另一个VC,我一直在学习。

let next = self.storyboard?.instantiateViewController(withIdentifier: "VerifyVC") as!
self.navigationController?.pushViewController(next, animated: true)

但现在因为我想在另一个项目中再次使用它,它不起作用!有人有任何想法吗?

答案

首先,您应该测试以确保导航控制器不是Sh_Khan所提到的nil。

如果它是零,那么您可能想要添加它。

 let next = self.storyboard?.instantiateViewController(withIdentifier: "VerifyVC") as!

let navigationController = UINavigationController(rootViewController: next)
self.present(viewController: navigationController, animated: true, completion: nil)

这将导致您创建一个新的导航控制器并在其中嵌入qazxsw poi viewController,然后按下navigationController。

祝好运

另一答案

这可能是您运行此代码的vc

next

inside没有嵌入到navigationController里面,所以这个

self.navigationController?.pushViewController(next, animated: true)

没有

因此没有推动

以上是关于导航控制器不能正常工作的主要内容,如果未能解决你的问题,请参考以下文章

导航组件:找不到 NavController

Android 4.4 — 半透明状态/导航栏 — fitSystemWindows/clipToPadding 不能通过片段事务工作

setNavigationBarHidden 不能以编程方式工作?

Android espresso 无法导航到其他 Fragment?

使用导航从工具栏菜单项单击在片段之间传递数据 - Kotlin

从其他片段(如导航链接)更改片段