gpt4 book ai didi

ios - 如何将数据从 View Controller 传递到导航 Controller ,然后再传递到另一个 View Controller ?

转载 作者:搜寻专家 更新时间:2023-10-31 22:43:02 25 4
gpt4 key购买 nike

我有来自 View Controller 的数据,我想传递另一个 View Controller ,但我已将其设置为模态显示,因此我在它们之间有一个导航 Controller 。如何将数据从第一个 View Controller 通过导航 Controller 传递到第二个 View Controller ?

我在第一个 View Controller 中有这段代码:

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "presentPopup"
{
let destViewController = segue.destination as! NavigationViewController
destViewController.myData2 = myData
}
// Get the new view controller using segue.destinationViewController.
// Pass the selected object to the new view controller.
}

然后导航 Controller 中的这段代码:

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
let destViewController = segue.destination as! SecondViewController
destViewController.myData3 = myData2
}

但它不起作用。

最佳答案

您可以在 First ViewController 中使用它:

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "presentPopup"
{
let destViewController = segue.destination as! NavigationViewController
let secondViewcontroller = destViewController.viewcontrollers.first as! SecondViewcontroller
secondViewcontroller.myData2 = myData
}
// Get the new view controller using segue.destinationViewController.
// Pass the selected object to the new view controller.
}

关于ios - 如何将数据从 View Controller 传递到导航 Controller ,然后再传递到另一个 View Controller ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43269235/

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