UIButton创建错误 - “无法识别的选择器发送到实例”

时间:2015-06-04 18:09:34

标签: swift uibutton

我已经使用此代码向我的视图添加了一个按钮,但是它出现错误“无法识别的选择器发送到实例”并导致应用程序崩溃。

有谁知道这是为什么?

非常感谢!

       let button: UIButton = UIButton(frame: CGRectMake(100, 400, 100, 50))
        button.backgroundColor = UIColor.clearColor()
        button.setTitle("go Back", forState: UIControlState.Normal)
        button.addTarget(self, action:  "buttonAction:", forControlEvents: UIControlEvents.TouchUpInside)
        self.view.addSubview(button)


    }

    func buttonAction(sender: UIButton!) {

        println("SegueSTGB")
        performSegueWithIdentifier("SegueSTGB", sender: self)

    }

1 个答案:

答案 0 :(得分:3)

您应该修改addTarget:

button.addTarget(self, action:Selector("buttonAction:"), forControlEvents: UIControlEvents.TouchUpInside)