[英]Value of type 'UIStackView' has no member 'text'
I am using the following code from the Apple developer website. 我正在使用Apple开发人员网站上的以下代码。 I followed their steps but my code creates an error.
我遵循了他们的步骤,但是我的代码创建了一个错误。 Can you please help me figure out what the problem is?
您能帮我找出问题所在吗?
Teh error I get is: 我得到的错误是:
Value of type 'UIStackView' has no member 'text'
类型'UIStackView'的值没有成员'text'
import UIKit
class ViewController: UIViewController {
// Mark: Properties
@IBOutlet weak var nameTextField: UITextField!
@IBOutlet weak var mealNameLabel: UIStackView!
@IBAction func setDefaultLabelText(_ sender: UIButton) {
mealNameLabel.text = "Default Text"
}
}
I presume that you have a label UITextField
, a UILabel
, and UIButton
in your storyboard. 我假设您在情节
UIButton
中具有标签UITextField
, UILabel
和UIButton
。 And you want to change the text in the mealNameLabel
label when the button is tapped. 当您点击按钮时,您想更改
mealNameLabel
标签标签中的文本。 So you should change the type of mealNameLabel
from UIStackView!
因此,您应该从
UIStackView!
更改mealNameLabel
UIStackView!
的类型UIStackView!
to UILabel
, since a UIStackView
doesn't have a text
property. 到
UILabel
,因为UIStackView
没有text
属性。
If you'd like to set the text in the label programmatically when the view loads then do so in viewDidLoad
: 如果您希望在加载视图时以编程方式设置标签中的文本,请在
viewDidLoad
:
override func viewDidLoad() {
super.viewDidLoad()
mealNameLabel.text = "Put here the text you want"
}
"Put here the text you want"
is just a sample String
, it could be nameTextField.text
if you want. "Put here the text you want"
只是一个示例String
,如果需要,可以为nameTextField.text
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.