【问题标题】:Open view controller programatically and dont see navigation bar. Swift 3以编程方式打开视图控制器并且看不到导航栏。斯威夫特 3
【发布时间】:2017-06-06 19:52:51
【问题描述】:

在我的故事板上,我在导航控制器中嵌入了一个集合视图控制器。现在从集合视图的单元格中,我以编程方式打开第二个视图控制器(称为 TwoPicsViewController),如下所示:

 let storyBoard : UIStoryboard = UIStoryboard(name: "Main", bundle:nil)

            let nextViewController = storyBoard.instantiateViewController(withIdentifier: "TwoPicsViewController") as! TwoPicsViewController


            self.present(nextViewController, animated:true, completion:nil)

但是,当我的 TwoPicsViewController 打开时,我根本看不到导航栏。在故事板上,我将 TwoPicsViewController 连接到第一个带有 segue 显示的视图控制器。

我还错过了什么吗?

谢谢

【问题讨论】:

    标签: swift uinavigationcontroller uicollectionview uinavigationbar


    【解决方案1】:

    要将新的UIViewController 推送到导航堆栈,您应该使用:

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

    代替:

    self.present(nextViewController, animated:true, completion:nil)
    

    【讨论】:

      【解决方案2】:

      您没有将新的 vc 放在导航堆栈上,试试这个:

      performSegue(withIdentifier: "Segue Name", sender: nil)
      

      在 Storyboard 上选择 Segue,属性检查器,标识符 = "Segue Name"

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-03-24
        • 1970-01-01
        • 2021-10-29
        • 2017-09-10
        • 2023-04-06
        相关资源
        最近更新 更多