我正在尝试从 UITableView 单元格的此结构内的变量获取数据
struct Issue {
var id: String
var tester: String
var type: issueType
var title: String
var appName: String
var desc: String
var date: Date
static func type(_ item: issueType) -> String {
if item == .major {
return "major"
}
else if item == .blocker {
return "blocker"
}
else if item == .minor {
return "minor"
}
return ""
}
}
但是每次我尝试获取标签的数据时,它都没有显示。这是我的 viewController 中的代码
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: identifier, for: indexPath)
let item = array[indexPath.row]
let topLine = cell.viewWithTag(1)
let labelStatus = cell.viewWithTag(2) as! UILabel
let labelTester = cell.viewWithTag(3) as! UILabel
let labelTitle = cell.viewWithTag(4) as! UILabel
let labelAppName = cell.viewWithTag(5) as! UILabel
let labelDesc = cell.viewWithTag(6) as! UILabel
let labelDate = cell.viewWithTag(7) as! UILabel
let labelId = cell.viewWithTag(8) as! UILabel
labelStatus.text = Issue.type(item.type).capitalized
labelTester.text = Issue.tester
return cell
}
附注labelStatus 文本工作正常
最佳答案
设置 labelStatus
的文本是有效的,因为您正在调用 Issue
类型的静态函数,并且该函数返回 String
。在第二种情况下,您尝试获取结构类型的属性,而不是特定item
的属性。
使用item
的属性
labelTester.text = item.tester
关于ios - 从不同类 Swift 中的结构内的变量获取数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53810868/