加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

“无法识别的选择器发送到实例”在swift

发布时间:2020-12-14 05:54:25 所属栏目:百科 来源:网络整理
导读:我不知道我在做错什么我也很新的编程,所以我不是很好的调试。这是一个测试应用程序,以便我可以看到应用程序开发有多快。到目前为止,我已经得到了: class ViewController: UIViewController,UITextViewDelegate { var textView: UITextView! init(nibName
我不知道我在做错什么我也很新的编程,所以我不是很好的调试。这是一个测试应用程序,以便我可以看到应用程序开发有多快。到目前为止,我已经得到了:
class ViewController: UIViewController,UITextViewDelegate {

    var textView: UITextView!

    init(nibName nibNameOrNil: String?,bundle nibBundleOrNil: NSBundle?) {
        super.init(nibName: nibNameOrNil,bundle: nibBundleOrNil)
    }

    override func viewDidLoad() {
        super.viewDidLoad()

        var widthField = self.view.bounds.size.width - 10
        var heightField = self.view.bounds.size.height - 69 - 221
        var textFieldString: String! = ""
        //Set up text field
        self.textView = UITextView(frame: CGRectMake(5,64,widthField,heightField))
        self.textView.backgroundColor = UIColor.redColor()
        self.view.addSubview(self.textView)
        //Set up the New button
        var newButtonString: String! = "New Note"
        var heightButton = 568 - heightField - 1000
        let newButton = UIButton(frame: CGRect(x: 5,y: 5,width: widthField,height: 50)) as UIButton
        UIButton.buttonWithType(UIButtonType.System)
        newButton.setTitle(newButtonString,forState: UIControlState.Normal)
        newButton.backgroundColor = UIColor.redColor()
        newButton.addTarget(self,action: "buttonAction:",forControlEvents: UIControlEvents.TouchUpInside)
        self.view.addSubview(newButton)

    }

    func buttonAction() {
        println("tapped button")
    }
}

当我按下iOS模拟器中的按钮时,我收到错误“无法识别的选择器发送到实例”。该应用程序打开正常,但按下按钮,它只是崩溃。

func buttonAction(){...

应该

func buttonAction(sender:UIButton!)
{
    println("tapped button")
}

因为newButton的动作:“buttonAction”,所以。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读