ios - 导航 Controller 从第二次转换开始显示

标签 ios swift uinavigationcontroller

为什么导航栏不是立即显示,而是在屏幕上经过几次转换后才显示?

第一个屏幕

First Screen

第二个屏幕

Second Screen

第三屏幕

Third Screen

第四个屏幕

Fourth Screen

Storyboard之间的转换是通过代码完成的

let storyboard = UIStoryboard(name: "detail", bundle: nil)
let vc = storyboard.instantiateViewController(withIdentifier: "Login") as! TwoViewController
self.present(vc, animated: true)

最佳答案

由于您正在呈现 View Controller 本身,因此它不会有任何导航 Controller 。如果您需要为 View Controller 提供导航 Controller ,请提供导航 Controller 而不是 View Controller 。

let storyboard = UIStoryboard(name: "detail", bundle: nil)
let vc = storyboard.instantiateViewController(withIdentifier: "navigationControllerID") as! UINavigationController
self.present(vc, animated: true)

或者 - 以编程方式使用 NavController 包装 VC。

let storyboard = UIStoryboard(name: "detail", bundle: nil)
let vc = storyboard.instantiateViewController(withIdentifier: "Login") as! TwoViewController
let nav = UINavigationController(rootViewController: vc)
self.present(nav, animated: true)

关于ios - 导航 Controller 从第二次转换开始显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52623900/

相关文章:

ios - 在 touchesMoved 期间取消触摸事件

ios - 使用 UINavigationController 时 UIStackView 无法设置底部约束

使用 nil 合并运算符的 Swift 编译时间

ios - URL : "gplus://" - error: 的 XCUITest 失败

iphone - 使用 MonoTouch 将自定义后退按钮添加到导航栏

ios - 以编程方式创建居中的 UIBarButton

ios - 通过选项卡栏设置嵌入导航 Controller 中的 View Controller 的属性

ios - 在 RxSwift 中处理绑定(bind)时如何不使观察者无效?

ios - 我什么时候应该在 Xcode 中勾选 "Also create XIB file"复选框?

ios - 如何在 UIView transitionWithView 之后运行代码?