我在视图上添加了一个按钮并使用 addTarget 绑定事件来调用 self.testp ,但是当我运行它时,发生了错误:
2015-06-19 23:08:29.237 UI[16978:1700826] -[UI.ViewController testp:]: unrecognized selector sent to instance 0x7864d4a0
2015-06-19 23:08:29.240 UI[16978:1700826] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UI.ViewController testp:]: unrecognized selector sent to instance 0x7864d4a0'
代码是:
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
var btn:UIButton = UIButton.buttonWithType(UIButtonType.DetailDisclosure) as! UIButton
btn.frame = CGRectMake(10, 150, 100, 30)
btn.setTitle("button", forState: UIControlState.Normal)
//!!!!!!DID NOT WORK
btn.addTarget(self, action: Selector("testp:"), forControlEvents: UIControlEvents.TouchUpInside);
self.view.addSubview(btn)
func testp(){
println("tttt")
}
}
}
为什么?!!