有值的DetailViewController中 定义闭包
//假如你想传个字符串
typealias MyColsure = (_ str: String) -> Void
某个事件触发方法
func backBtnClick() {
if self.myColsure != nil {
self.myColsure!("我是传回去的值")
}
_ = self.navigationController?.popViewController(animated: true)
}
当前需要得到值的VC的某个事件触方法
func sendBtnClick() {
let vc = DetailViewController()
//闭包传值
vc.myColsure = {
(backStr: String) -> Void in
self.textField.text = backStr
}
self.navigationController?.pushViewController(vc, animated: true)
}
坚持每天走一小步 勤能补拙 何况我这么有天赋 ~