0
我在youtube上跟随了一个关于Swift的Hello World程序的在线教程。即使我像教程中的代码一样键入代码,它直到给我一个调试错误(绿色错误)。我研究了这样的问题,但代码复杂并且超出了我的头脑。通常我用java编码,但我一直想为移动开发。无论如何,如果你能告诉我: 1.错误的含义。 2.我如何解决它。 3.我怎样才能防止这样的错误。Swift:当我试图让我的程序工作时,我得到调试“错误”
NameLabel.text =“嗨(nameTextField.text)”是我得到错误的线。 这里是我的代码:
import UIKit
class ViewController: UIViewController {
@IBOutlet var NameLabel: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
@IBAction func HelloWorldAction(nameTextField: UITextField) {
NameLabel.text = "Hi \(nameTextField.text)"
}
}
你是怎么调用HelloWorldAction函数的?它看起来很奇怪,试图通过TextField作为函数的参数。如果TextField是另一个IBoutlet,那么以后您可以获取该值会更容易。 (I.E .:一个按钮会调用该动作,并从TextField获取字符串)。 – romsearcher
发布调试器输出。 – Bigfoot11