gpt4 book ai didi

ios - Swift:通过 presentViewController 传递导航栏

转载 作者:搜寻专家 更新时间:2023-11-01 05:50:18 25 4
gpt4 key购买 nike

在我的 Storyboard中有导航 Controller 、viewContrl1 和 viewContrl2。对于下一次更新,我必须设法将 viewContrl2 连接到另一个 viewContrl2 实例。

从 stackOverflow 获得一些帮助后,我通过以下方式管理它:

let newView2 : ViewContrl2 = UIStoryboard(name: "Main", bundle: nil).instantiateViewControllerWithIdentifier("viewContrl2") as! ViewContrl2
...
...
view2.presentViewController(newView2, animated: true, completion: nil)

它实际上完全符合我的要求,但顶部没有导航栏。在 ViewContrl2 类中,有 @IBOutlet weak var navigation: UINavigationItem!,我直接从 StoryBoard 连接了它。但是,导航在新创建的 viewControl2 中似乎不起作用。我需要这个,因为用户必须能够按下返回并返回到上一个 View 。任何人都可以解决这个问题吗?

谢谢

最佳答案

为了能够返回,您需要使用现有的导航 Controller 。只需添加一个检查以确保。

let newView2 : ViewContrl2 = UIStoryboard(name: "Main", bundle: nil).instantiateViewControllerWithIdentifier("viewContrl2") as! ViewContrl2

if let navCtrl = self.navigationController
{
navCtrl.pushViewController(newView2, animated: true)
}
else
{
let navCtrl = UINavigationController(rootViewController: newView2)
self.presentViewController(navCtrl, animated: true, completion: nil)
}

关于ios - Swift:通过 presentViewController 传递导航栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38779023/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com