我不断收到错误消息,"类型值' UIStackView'没有会员'委托'"当我添加" nameTextField.delegate = self"时,我的代码的第21行部分。有任何想法吗?我最初以为我没有添加协议,但它与指南相符....
import UIKit
class ViewController: UIViewController, UITextFieldDelegate {
// MARK: Properties
@IBOutlet weak var nameTextField: UIStackView!
@IBOutlet weak var mealNameLabel: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
// Handle the text field's user input through delegation callbacks
nameTextField.delegate = self
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
// MARK: UITextFieldDelegate
func textFieldShouldReturn(textField: UITextField) -> Bool {
// Hide the keyboard
textField.resignFirstResponder()
return true
}
// MARK: Actions
@IBAction func setDefaultLabelText(sender: UIButton) {
mealNameLabel.text = "Default Test Text"
}
}
答案 0 :(得分:3)
@vadian指出,UITextField
绝对不同于UIStackView
。
更改此行:
@IBOutlet weak var nameTextField: UIStackView!
到此:
@IBOutlet weak var nameTextField: UITextField!
这可能需要您重新连接插座。