有值的DetailViewController中 定義閉包
//假如你想傳個(gè)字符串
typealias MyColsure = (_ str: String) -> Void
某個(gè)事件觸發(fā)方法
func backBtnClick() {
if self.myColsure != nil {
self.myColsure!("我是傳回去的值")
}
_ = self.navigationController?.popViewController(animated: true)
}
當(dāng)前需要得到值的VC的某個(gè)事件觸方法
func sendBtnClick() {
let vc = DetailViewController()
//閉包傳值
vc.myColsure = {
(backStr: String) -> Void in
self.textField.text = backStr
}
self.navigationController?.pushViewController(vc, animated: true)
}
堅(jiān)持每天走一小步 勤能補(bǔ)拙 何況我這么有天賦 ~