为什么我得到的信号SIGABRT,当我选择创建按钮? [英] Why do I get signal SIGABRT when I select a created button?

查看:149
本文介绍了为什么我得到的信号SIGABRT,当我选择创建按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在SWIFT 2创建一个按钮,当我选择它,我得到的信号SIGABRT和应用程序崩溃。继承人的code:

 让按钮=的UIButton()//(类型:UIButtonType.System)作为的UIButton!
    button.setTitle(按钮,forState:。正常)
    button.setTitleColor(UIColor.blueColor(),forState:。正常)
    button.addTarget(个体经营,动作按钮pressed:forControlEvents:UIControlEvents.TouchUpInside)
    button.frame = CGRectMake(100,100,100,100)
    self.view.addSubview(按钮)
    FUNC按钮pressed(发件人:UIButton的){
        打印(ButtonIsSelected)
    }

这使我对AppDelegate.swift,并在中间的的NSLog 它说:无法识别的选择发送到实例...
请帮忙。安东


解决方案

  FUNC按钮pressed(发件人:UIButton的){
    打印(ButtonIsSelected)
}

这个方法必须是在你的类主体不是在函数体。正如我猜你已经做了。

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

解决方案

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

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

这篇关于为什么我得到的信号SIGABRT,当我选择创建按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆