swift - 为什么我的 UIButton 的目标从未达到?

标签 swift uibutton

    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 中的触摸?

最佳答案

像这样使用,因为它需要绑定(bind)到 IBAction

@IBAction func addBinderTapped(sender: UIButton)
{
}

通过命令+拖动到 Storyboard按钮来连接此操作与您的按钮以绑定(bind)此功能。

关于swift - 为什么我的 UIButton 的目标从未达到?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26619872/

相关文章:

iphone - 无法在 iPhone 中实现单选按钮

ios - tableviewcell重复uibuttons

iphone - UIButton 放置在 tableviewcell 顶部

objective-c - Xcode : How do I remove an action from a object?

ios - UITableView 中的两个自定义单元格

ios - 是否有 WWDC 2019 session 视频摘要?

ios - 如何成功处理sftp ://protocol by subclassing NSURLProtocol?

ios - Swift 2.0 OneSignal .pushNotification

ios - 使用超过 1 个 Prototype Cell 时 UITableView 的奇怪行为

ios - 按钮操作不适用于 View 上的按钮