【发布时间】:2018-12-17 07:48:37
【问题描述】:
我正在尝试从这个结构中的变量中为我的 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 文本工作正常
【问题讨论】:
-
您应该使用
switch。我想有一个不同的问题类型,switch会告诉你。另外,没有理由使用静态方法,使用普通方法和self.type。