func setupNewBinderButton() {
let binderButton = UIButton.buttonWithType(UIButtonType.Custom) as UIButton
binderButton.frame = CGRectMake(50, 384-25, 50, 50)
binderButton.setTitle("Add", forState: UIControlState.Normal)
binderButton.setTitleColor(UIColor.blackColor(), forState: UIControlState.Normal)
binderButton.addTarget(self, action: "addBinderTapped", forControlEvents: UIControlEvents.TouchUpInside)
binderButton.userInteractionEnabled = true
self.view.addSubview(binderButton)
}
func addBinderTapped() {
println("hi")
abort()
}
override func viewDidLoad() {
super.viewDidLoad()
setupNewBinderButton()
我在此函数中设置的断点没有命中。日志未命中。中止不会发生。
如何使我的UIButton响应Swift中的触摸?
最佳答案
像这样使用,因为它需要绑定到IBAction
@IBAction func addBinderTapped(sender: UIButton)
{
}
通过命令+拖动到情节提要按钮将此操作与您的按钮关联,以绑定此功能。