有谁能告诉我如何将值从swift中导航控制器中的第二个场景传递到第一个通过某个按钮实际驱动到第二个场景的场景。我不能使用准备segue函数,因为它仅在调用时调用从塞古的尾部移动到它的头部。
答案 0 :(得分:0)
听起来像代表模式的工作!
protocol SecondViewControllerDelegate: class {
func secondViewController(controller: SecondViewController, passVariable variable: Int)
}
class SecondViewController {
weak var delegate: SecondViewControllerDelegate?
...
func ButtonTappped(sender: AnyObject) {
delegate?.secondViewController(self, passVariable: 10)
}
}
class FirstViewController: SecondViewControllerDelegate {
func prepareForSegue(segue: UIStoryboardSegue) {
if let controller = segue.destinationViewController as? SecondViewController {
controller.delegate = self
}
}
// MARK: SecondViewControllerDelegate
func secondViewController(controller: SecondViewController, passVariable variable: Int) {
// Here we go!
}
}