Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/logging/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 为什么在选择已创建的按钮时会收到信号SIGABRT?_Ios_Button_Swift2_Sigabrt - Fatal编程技术网

Ios 为什么在选择已创建的按钮时会收到信号SIGABRT?

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

我正在swift 2中创建一个
按钮,当我选择它时,收到信号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应该在类方法级别定义,而不是在设置方法中定义。谢谢。现在效果很好!