您无法在中传递自定义参数
addTarget:。另一种方法是设置
tagbutton 的属性并根据标签进行工作。
button.tag = 5button.addTarget(self, action: "buttonClicked:", forControlEvents: UIControlEvents.TouchUpInside)
或对于 Swift 2.2 及更高版本:
button.tag = 5button.addTarget(self,action:#selector(buttonClicked), forControlEvents:.TouchUpInside)
现在基于
tag属性做逻辑
@objc func buttonClicked(sender:UIButton){ if(sender.tag == 5){ var abc = "argOne" //Do something for tag 5 } print("hello")}


