gpt4 book ai didi

swift - "Unrecognized selector sent to instance" swift

转载 作者:IT王子 更新时间:2023-10-29 05:06:03 26 4
gpt4 key购买 nike

我不知道我做错了什么。我对编程也很陌生,所以我不太擅长调试。这是一个测试应用程序,因此我可以看到它与应用程序开发的结合有多 swift 。到目前为止,我得到了这个:

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 的 action: "buttonAction:" 所以。

关于swift - "Unrecognized selector sent to instance" swift ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24094620/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com