Ios 为什么在选择已创建的按钮时会收到信号SIGABRT?
我正在swift 2中创建一个Ios 为什么在选择已创建的按钮时会收到信号SIGABRT?,ios,button,swift2,sigabrt,Ios,Button,Swift2,Sigabrt,我正在swift 2中创建一个按钮,当我选择它时,收到信号SIGABRT,应用程序崩溃。代码如下: let button = UIButton()//(type: UIButtonType.System) as UIButton! button.setTitle("button", forState: .Normal) button.setTitleColor(UIColor.blueColor(), forState: .Normal) button.addTa
按钮,当我选择它时,收到信号SIGABRT,应用程序崩溃。代码如下:
let button = UIButton()//(type: UIButtonType.System) as UIButton!
button.setTitle("button", forState: .Normal)
button.setTitleColor(UIColor.blueColor(), forState: .Normal)
button.addTarget(self, action: "buttonPressed:", forControlEvents: UIControlEvents.TouchUpInside)
button.frame = CGRectMake(100, 100, 100, 100)
self.view.addSubview(button)
func buttonPressed(sender: UIButton!) {
print("ButtonIsSelected")
}
它把我带到AppReavaT.SWIFT,在NSLog的中间,它说:发送给实例的未识别选择器…
请帮忙。安东
func buttonPressed(sender: UIButton!) {
print("ButtonIsSelected")
}
此方法必须位于类主体中,而不是函数主体中。我想您已经这样做了。按钮pressed应该在类方法级别定义,而不是在设置方法中定义。谢谢。现在效果很好!