Swift中页面逆向传值

来源:互联网 发布:如何查mac地址值那个大 编辑:程序博客网 时间:2024/05/16 05:43

A页面 创建按钮,跳到B页面

let btn = UIButton(type: UIButtonType.Custom)self.myBtn = btnbtn.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)    }
0 0
原创粉丝点击