0
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的目标永远不会到达?
如何让我的UIButton在Swift中响应触动?
http://stackoverflow.com/questions/25056278/swift-access-control-with-target-selectors/25056424#25056424 – 2014-10-28 22:53:42
http://stackoverflow.com/questions/26449053/strongly-typed-selectors-in -swift/26454949#26454949 – 2014-10-28 22:54:50
没有骰子。我尝试使用动作:选择器(“addBinderTapped:”)和@objc func addBinderTapped(按钮:UIButton!){作为链接引用。 – quantumpotato 2014-10-28 22:56:09