以下是我的代码,我在我的函数中访问cell
,但我收到nil
。
private func setDataForStatusLabel(stausText: String, statusColor: UIColor) {
let indexPath = IndexPath(row: 0, section: 0)
let cell = tableView.cellForRow(at: indexPath) as? CustomLocateVehicleCell
if let cell = cell {
cell.statusLabel.text = stausText
cell.containerStatusLabel.text = stausText
cell.statusLabel.textColor = statusColor
cell.containerStatusLabel.textColor = statusColor
cell.statusColorView.backgroundColor = statusColor
cell.containerStatusColorView.backgroundColor = statusColor
}
}
答案 0 :(得分:0)
最后通过传递cell
参数
private func setDataForStatusLabel(stausText: String, statusColor: UIColor, cell: CustomLocateVehicleCell) {
cell.statusLabel.text = stausText
cell.containerStatusLabel.text = stausText
cell.statusLabel.textColor = statusColor
cell.containerStatusLabel.textColor = statusColor
cell.statusColorView.backgroundColor = statusColor
cell.containerStatusColorView.backgroundColor = statusColor
}
答案 1 :(得分:-3)
使用dequeueReusableCell
let cell = tblView.dequeueReusableCell(withIdentifier: "CustomLocateVehicleCell") as! CustomLocateVehicleCell
cell.configureCell(stausText, statusColor)