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中的触摸?
答案 0 :(得分:1)
使用这样,因为它需要绑定到IBAction
@IBAction func addBinderTapped(sender: UIButton)
{
}
通过命令将此操作与按钮连接+拖动到情节提要按钮以绑定此功能。