我需要通过popView将一些数据从secondView发送回First View。如何通过popViewControllerAnimated发回数据?
谢谢!
您可以使用 delegate
delegate
protocol
ChildViewController
MainViewController
navigate
例
在ChildViewController中 : 在 下面编写代码…
protocol ChildViewControllerDelegate { func childViewControllerResponse(parameter) } class ChildViewController:UIViewController { var delegate: ChildViewControllerDelegate? .... }
在MainViewController中
// extend `delegate` class MainViewController:UIViewController,ChildViewControllerDelegate { // Define Delegate Method func childViewControllerResponse(parameter) { .... // self.parameter = parameter } }
有两种选择:
A)与塞格
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) { let goNext = segue.destinationViewController as ChildViewController goNext.delegate = self }
B)没有塞格
let goNext = storyboard?.instantiateViewControllerWithIdentifier("childView") as ChildViewController goNext.delegate = self self.navigationController?.pushViewController(goNext, animated: true)
方法调用
self.delegate?.childViewControllerResponse(parameter)