导航到特定视图时导航栏消失
Nav bar disappears when navigating to a specific view
我有一个 UINavigationController
并且我推送和弹出视图,但在某些视图中,我想从堆栈转到特定视图,所以我使用了这段代码。它有效,但导航栏消失了。
for controller in self.navigationController!.viewControllers as Array {
if controller.isKind(of: HomeViewController.self) {
self.navigationController!.popToViewController(controller, animated: true)
break
}
}
在您的 HomeViewController 中,您可以尝试以下操作:
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
self.navigationController?.setNavigationBarHidden(false, animated: animated)
}
您可以按照 Idem 的评论中提到的那样以编程方式显示导航栏,或者如果您使用的是 XCode 界面构建器,您可能还需要确保为模拟指标中的每个视图正确定义状态栏视图属性区域 - 这适用于非故事板布局。
Simulated Metrics Section of properties in XCode Interface Builder
你可以尝试回答@ldem提出的问题
不过,您也可以尝试呈现视图而不是弹出
所以改变
self.navigationController!.popToViewController(controller, animated: true)
至
self.present(controller, animated: true, completion: nil)
我有一个 UINavigationController
并且我推送和弹出视图,但在某些视图中,我想从堆栈转到特定视图,所以我使用了这段代码。它有效,但导航栏消失了。
for controller in self.navigationController!.viewControllers as Array {
if controller.isKind(of: HomeViewController.self) {
self.navigationController!.popToViewController(controller, animated: true)
break
}
}
在您的 HomeViewController 中,您可以尝试以下操作:
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
self.navigationController?.setNavigationBarHidden(false, animated: animated)
}
您可以按照 Idem 的评论中提到的那样以编程方式显示导航栏,或者如果您使用的是 XCode 界面构建器,您可能还需要确保为模拟指标中的每个视图正确定义状态栏视图属性区域 - 这适用于非故事板布局。 Simulated Metrics Section of properties in XCode Interface Builder
你可以尝试回答@ldem提出的问题
不过,您也可以尝试呈现视图而不是弹出
所以改变
self.navigationController!.popToViewController(controller, animated: true)
至
self.present(controller, animated: true, completion: nil)