I'm trying to change the color of a label (or labels) in a cell if the value of alarmLevel != "0". This is what I have so far and it's changing the color of the cell.locationLabel in all of the cells instead of just the ones that satisfy the if statement. I'm sure its something to do with the indexPath but I cant figure it out.
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = myTableView.dequeueReusableCell(withIdentifier: cellId, for: indexPath) as! ViewControllerTableViewCell
cell.locationLabel.text = eventsList[indexPath.row].location
cell.eventTimeLabel.text = eventsList[indexPath.row].dateTime
cell.eventTypeLabel.text = eventsList[indexPath.row].agencyEventSubtypeCode
cell.agencyIdLabel.text = eventsList[indexPath.row].agencyId
if alarmLevel != "0" {
cell.locationLabel.textColor = UIColor.red
} else {
cell.locationLabel.textColor = UIColor.black
}
return cell
}
alarmLevel
value for every execution oftableView(_:cellForRowAt:)
. You might want to use the appropriate value, similar as you did for the other properties.