场景:A页面跳转到B页面,B页面返回到A页面,(B页面给A页面传值)
B页面逻辑:创建block,声明变量,传值
A页面逻辑:回调
B页面代码:
1、创建block
typealias SecondViewControllerBlock = (String,Int)->Void
2、声明block 变量
var block : SecondViewControllerBlock?
3、传值
@IBAction func back(_sender:UIButton) {
ifself.block!=nil{
self.block!(passTf.text??"",26)
}
self.navigationController?.popViewController(animated:true)
}
A页面代码:
block 回调
@IBAction func next(_sender:UIButton) {
let secondVC =SecondViewController()
secondVC.block= {
(name,age)in
self.textLabel.text=String(format:"%@%d", name,age)
}
self.navigationController?.pushViewController(secondVC, animated:true)
}
网友评论