Why do I get signal SIGABRT when I select a create

2019-08-13 02:40发布

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条回答
你好瞎i
2楼-- · 2019-08-13 02:54
func buttonPressed(sender: UIButton!) {
    print("ButtonIsSelected")
}

This method must be in your class body not in function body . As I guess you have done.

查看更多
登录 后发表回答