Ios 访问外部单元格时获取零
下面是我的代码,我正在函数中访问Ios 访问外部单元格时获取零,ios,uitableview,swift3,Ios,Uitableview,Swift3,下面是我的代码,我正在函数中访问单元格,但我得到的是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
单元格
,但我得到的是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
}
}
使用dequeueReusableCell
let cell = tblView.dequeueReusableCell(withIdentifier: "CustomLocateVehicleCell") as! CustomLocateVehicleCell
cell.configureCell(stausText, 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
}
您只能获取屏幕上可见的单元格。1。细胞在屏幕上可见吗?2是否为
CustomLocateVehicleCell
类型的单元格?@ozgur 1.是2.是否为CustomLocateVehicleCell
类型的单元格?@ReinierMelian是