@H_403_2@var inteface:((Int) -> Void)? @IBOutlet weak var num: UIButton! override func viewDidLoad() { super.viewDidLoad() num.addTarget(self,action: "onNumClick:",forControlEvents: UIControlEvents.TouchUpInside) } func onNumClick(sender :UIButton){ if(inteface != nil){ inteface!(sender.tag) } } func addOnClick(tag : Int,onclick : (Int) -> Void){ num.tag = tag inteface = onclick }
匿名接口,swift 比java更随意,连接口名字也不用,直接定义直接传递,一门牛哄哄的语言