我已经使用这段代码在我的 View 中添加了一个按钮,但是它出现了错误“无法识别的选择器发送到实例”并使应用程序崩溃。
有人知道这是为什么吗?
非常感谢!
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)
}
最佳答案
你应该修改addTarget:
button.addTarget(self, action:Selector("buttonAction:"), forControlEvents: UIControlEvents.TouchUpInside)
关于swift - UIButton 创建错误 - "unrecognized selector sent to instance",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30651112/