gpt4 book ai didi

ios - swift 3 : How to make sure that data is set before presenting in next view controller

转载 作者:行者123 更新时间:2023-11-28 08:04:57 24 4
gpt4 key购买 nike

我正在使用 prepare for segue 在另一个 View Controller 中设置字典变量。但问题是 View Controller 在没有数据的情况下打开 map 。如何确保只有在设置了字典变量数据后才转到下一个 View Controller 。

这是我的代码

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "showMapSegue"
{
if let mapVC = segue.destination as? MapVC
{
if vendorStoreKeys.count != 0{
mapVC.vendorStore = vendorStoreKeys
}
}
}
}

但是当 Controller 可见时,下一个 View Controller 中的供应商存储数组仍然是空的。它会在一段时间后设置数据,但此时我无法重新加载该 View Controller ,因此我需要确保在正确设置 ma​​pVC.vendorStore 变量之前我不会转到下一个 View Controller .

最佳答案

我能够解决这个问题。准备应该在调用之前设置数据,它是。问题是我实际上忘记删除 Storyboard 中直接从按钮到新 View Controller 的转场。这就是我所做的

  1. Removed the segue which was going directly from the collection view cell button to the next story board
  2. Created a new segue from the top of the view controller to the next view controller
  3. Named that segue "showMapSegue"

构建并运行。我在下一个 View Controller 中成功获取了数据。希望对您有所帮助。

关于ios - swift 3 : How to make sure that data is set before presenting in next view controller,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45458908/

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