以下是我的代码,我正在访问我的功能中的 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
}
}
最终通过传递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
}
使用Dequeuereusablecell
let cell = tblView.dequeueReusableCell(withIdentifier: "CustomLocateVehicleCell") as! CustomLocateVehicleCell
cell.configureCell(stausText, statusColor)
- ,但在此之前,请确保将UitaiteViewCell拖放并丢弃在UITATION VIEW上
- 使用CustomLocatovehicleCell 更改单元格类
- 设置标识符CustomLocateVehicleCell
- configurecell在CustomLocateLocateVehicleCell中创建此方法,并在托管单元的颜色和文本 的位置编写您的代码