繁体   English   中英

从 Bar Button 项目导航到导航 controller

[英]Navigate from Bar Button item to navigation controller

我有一个带有条形按钮项目的视图 controller,并且在此按钮上执行一个操作以从视图导航到另一个导航视图 controller,但是当我导航到导航 Z594C103F2C6E04C3D8AB059F031E0C1 时,导航栏被隐藏了!

我的导航代码

guard let window = UIApplication.shared.keyWindow else { return }
    let sb = UIStoryboard(name: "Main", bundle: nil)
    let vc = sb.instantiateViewController(identifier: "AdPostViewController")
    window.rootViewController = vc
    UIView.transition(with: window, duration: 0.5, options: .transitionCrossDissolve, animations: nil, completion: nil)

to clarify I did not declare isNavigationBarhidden in the code, I am embedding a view controller to navigation controller, and when I navigate from the main view controller to the navigation controller I see the bar is hidden and I want to show it

您可以设置isNavigationBarHidden 苹果记录如下:

默认值为假。 设置此属性会更改导航栏的可见性,而不会为更改设置动画。 如果要为更改设置动画,请改用 setNavigationBarHidden(_:animated:) 方法。

我建议不要更改window.rootViewController而是显示视图 controller :

func present(_ viewControllerToPresent: UIViewController, 
    animated flag: Bool, 
  completion: (() -> Void)? = nil)

你的代码变成:

        let sb = UIStoryboard(name: "Main", bundle: nil)
        let vc = sb.instantiateViewController(identifier: "AdPostViewController")
        vc.modalTransitionStyle = .crossDissolve
        self.present(vc, animated: true, completion: nil)

编辑:您应该检查 AdPostViewController 是否是AdPostViewController中的 navigationController 的标识符。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM