【发布时间】:2018-06-01 18:57:43
【问题描述】:
我在主 viewController 上有一个按钮,其默认值 nil 与 dropDown pod 关联。
在同一个viewController 上还有一个容器视图。
在第一次加载时,我从共享首选项中获取变量的默认值,并将该值通过performSegue 传递给容器视图。
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if(segue.identifier == "dataToContainerView"){
DispatchQueue.main.async {
var secondVC = segue.destination as! secondViewController //container viewController
secondVC.variable = self.variable
}
}
}
现在我需要通过用户从dropdown 按钮中选择来再次传递相同变量的值。
dropDown.selectionAction = { [unowned self] (index, item) in
self.button.setTitle(item, for: UIControlState())
self.variable = item
print(item)
self.performSegue(withIdentifier: "dataToContainerView", sender: nil)
//performing segue to resend the new value of the variable.
}
上述代码在print(item) 之前正常运行。
但是我在 performSegue 上收到以下错误。
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'There are unexpected subviews in the container view. Perhaps the embed segue has already fired once or a subview was added programmatically?
我应该如何在dropDown pod 的帮助下将值第二次覆盖第一个值传递给容器视图?
更新:- 我需要变量值,以便我可以将它传递给容器 viewController 上的 json 解析器。并且容器 viewController 上的代码重新执行。
【问题讨论】:
-
你可以通过委托传递它。
-
你不能这样做,正如错误所说的那样。一种解决方案是设置自定义闭包或使用委托。
-
@DharmeshKheni 请指导我或帮助我编写一些代码以找出解决方案
标签: ios swift dropdown uicontainerview