cuốn sách gpt4 ai đã làm

swift - 类型 'String' 的 UILabel 值没有成员 'text'(静态自定义单元格)

In lại Tác giả: Walker 123 更新时间:2023-11-28 15:22:29 26 4
mua khóa gpt4 Nike

我正在从 json 中获取用户信息,但是当我将值分配给我的标签时,它显示错误 (Value of type 'String' have no member 'text').

是因为Custom static table cell吗?如何解决?我的基础不好...

nhập mô tả hình ảnh ở đây
并且:

nhập mô tả hình ảnh ở đây

câu trả lời hay nhất

使用不同的变量名。具有唯一变量名的好习惯

由于变量名称与变量值相同,您会收到错误

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
}
}

关于swift - 类型 'String' 的 UILabel 值没有成员 'text'(静态自定义单元格),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45754304/

26 4 0
Chứng chỉ ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com
Xem sitemap của VNExpress