button.addTarget(self,action: "buttonClicked:",forControlEvents: UIControlEvents.TouchUpInside)
任何我的buttonClicked方法:
func buttonClicked(sender:UIButton) { println("hello") }
任何人的想法?
谢谢你的帮助。
button.addTarget(self,action: "buttonClicked:",forControlEvents: UIControlEvents.TouchUpInside)
任何我的buttonClicked方法:
func buttonClicked(sender:UIButton) { println("hello") }
任何人的想法?
谢谢你的帮助。
button.tag = 5 button.addTarget(self,forControlEvents: UIControlEvents.TouchUpInside)
或者对于Swift 2.2和更高版本:
button.tag = 5 button.addTarget(self,action:#selector(buttonClicked),forControlEvents:.TouchUpInside)
func buttonClicked(sender:UIButton) { if(sender.tag == 5){ var abc = "argOne" //Do something for tag 5 } print("hello") }