我不知道我在做错什么我也很新的编程,所以我不是很好的调试。这是一个测试应用程序,以便我可以看到应用程序开发有多快。到目前为止,我已经得到了:
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”,所以。