A页面 创建按钮,跳到B页面
let btn = UIButton(type: UIButtonType.Custom)
self.myBtn = btn
btn.frame = CGRectMake(50, 50, 50, 50)
btn.setTitle("nextVC", forState: UIControlState.Normal)
btn.addTarget(self, action: "nextVC", forControlEvents: UIControlEvents.TouchUpInside)
self.view.addSubview(btn)
func nextVC(){
let nextVC = NextViewController()
nextVC.nextPara = {(num:Int) -> Void in
self.myBtn.setTitle("\(num)", forState: UIControlState.Normal)
}
self.navigationController?.pushViewController(nextVC, animated: true)
}
B页面 返回A页面传值
typealias loginClosure = (num:Int)->Void
let btn = UIButton(type: UIButtonType.Custom)
btn.frame = CGRectMake(50, 100, 100, 50)
btn.setTitle("preVC", forState: UIControlState.Normal)
btn.addTarget(self, action: "preVC", forControlEvents: UIControlEvents.TouchUpInside)
self.view.addSubview(btn)
func preVC(){
nextPara(num:12)
self.navigationController?.popViewControllerAnimated(true)
}