为什么当我select创build的button时,会收到SIGABRT信号?

我在swift 2中创build一个button ,当我select它,我得到信号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") } 

它带我到AppDelegate.swift和NSLog的中间它说:无法识别的select器发送到实例…请帮助。 安东

 func buttonPressed(sender: UIButton!) { print("ButtonIsSelected") } 

这个方法必须在你的类体中不在函数体中。 我猜你已经完成了。