问题
I'm creating a button
in swift 2 and when I select it, I get signal SIGABRT and the app crashes. Heres the code:
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")
}
It brings me to AppDelegate.swift and in the middle of the NSLog
it says: unrecognized selector sent to instance...
Please help. Anton
回答1:
func buttonPressed(sender: UIButton!) {
print("ButtonIsSelected")
}
This method must be in your class body not in function body . As I guess you have done.
来源:https://stackoverflow.com/questions/34477470/why-do-i-get-signal-sigabrt-when-i-select-a-created-button