我正在从 json 中获取用户信息,但是当我将值分配给我的标签时,它显示错误 (Value of type 'String' have no member 'text')
.
是因为Custom static table cell吗?如何解决?我的基础不好...
并且:
使用不同的变量名。具有唯一变量名的好习惯
由于变量名称与变量值相同,您会收到错误
UILabel 的名称为 empNameLabel : UILabel
(在 viewDidLoad
中),值也有相同的名称。
Thay đổi
let empNameLabel = user!["crew_name"] as? String //conflicting name with UILabel iboutlet
đến
let empNameValue = user!["crew_name"] as? String //variable name is unique
此外,您不应该强制解包选项(在您的情况下为 user
)
nên
var empNameValue = ""
if let unwrappedUser = user {
if let empNameValue = unwrappedUser["crew_name"] as? String {
empNameLabel.text = empNameValue //assign value to UILabel
}
}
Tôi là một lập trình viên xuất sắc, rất giỏi!