Swift: Force show Navigation Bar in Modal

一曲冷凌霜 提交于 2020-01-01 02:01:50

问题


I have the following Storyboard Segue in my Swift project:

The animation is correct, but there is no navigation bar in the destination view controller. I want to force the destination view controller to have a navigation bar. I tried in the destination view controller:

override func viewWillAppear(animated: Bool) {
    super.viewWillAppear(true)
    navigationController?.navigationBar.hidden = false
}

Or:

override func viewWillAppear(animated: Bool) {
    self.navigationController?.setNavigationBarHidden(false, animated: true)
}

But it refuses to show any navigation bar.

How can I perform a vertical segue (like "Cover Vertical") but still display a translucent Navigation bar in the destination view controller?

Edit: My Attributes inspector for the destination view controller:


回答1:


Try to create the Segue to a Navigation controller instead of your view controller. Navigation bars are only shown for view controllers in a navigation stack. In your case, the source view controller seems to be in a navigation stack but not the presented view controller. Try something like this:



来源:https://stackoverflow.com/questions/28401210/swift-force-show-navigation-bar-in-modal

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!