yanColor()
self.view.addSubview(button)
// Do any additional setup after loading the view.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
// 返回按钮实现
func buttonAction() {
// 闭包调用
self.block("block返回值")
self.navigationController?.popViewControllerAnimated(true)
}
// 在第一个视图控制器实现闭包
class FirstViewController: UIViewController {
var secondVC: SecondViewController! = SecondViewController()
override func viewDidLoad() {
super.viewDidLoad()
self.view.backgroundColor = UIColor.grayColor()
// 创建跳转按钮
let button: UIButton = UIButton(frame: CGRectMake(10,100,50,50))
button.addTarget(self, action: Selector("pushAction"), forControlEvents: UIControlEvents.TouchUpInside)
button.setTitle("push", forState: UIControlState.Normal)
button.backgroundColor = UIColor.cyanColor()
self.view.addSubview(button)
// Do any additional setup after loading the view.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
// push按钮方法实现
func pushAction(){
secondVC.view.backgroundColor = UIColor.orangeColor()
// 闭包实现
secondVC.block = {
str in
print(str)
}
self.navigationController?.pushViewController(secondVC, animated: true)
}
|