类型的价值' UIStackView'没有会员'委托' - Swift初学者指南

时间:2016-02-14 17:20:32

标签: ios iphone swift user-interface

大家早上好, 我是Swift的新手,我试图浏览Apple网站上的指南,而且我被困在这个页面上:

https://developer.apple.com/library/ios/referencelibrary/GettingStarted/DevelopiOSAppsSwift/Lesson3.html#//apple_ref/doc/uid/TP40015214-CH22-SW1

我不断收到错误消息,"类型值' 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"
}

}

1 个答案:

答案 0 :(得分:3)

@vadian指出,UITextField绝对不同于UIStackView

更改此行:

@IBOutlet weak var nameTextField: UIStackView!

到此:

@IBOutlet weak var nameTextField: UITextField!

这可能需要您重新连接插座。