В методе didSelectRow в UITableView я изменяю contentView.backgroundColor UITableViewCell, но у меня есть 2 раздела, и когда я отливаю ячейку с помощью:
let selectedCell:UITableViewCell = tableView.cellForRow(at: indexPath)!
и устанавливаю selectedCell.contentView.backgroundColor
, код изменяетbackgroundColor обоих разделов. Как преобразовать ячейку только из indexPath.section
?
ОБНОВЛЕНИЕ ОТ ответа @rmaddy
Когда я сохраняю в переменных indexPath.row и indexPath.section в методе didSelectRow и использую переменныев ячейке willDisplay или cellForRow для установки backgroundColor автоматически устанавливается backgroundColor для каждой строки 8-16-32-64.
ОБНОВЛЕНИЕ 2: в cellForRow я устанавливаю следующее:
if(indexPath.row == selectedFromIndex && indexPath.section == selectedFromSection){
cell.contentView.backgroundColor = UIColor(red: 0, green: 0, blue: 200, alpha: 0.1)
}else{
cell.backgroundColor = .clear
cell.isSelected = false
}
selectedFromIndex и selectedFromSection являются переменными, сохраненными в didSelectRowMethod. Выбор все еще появляется в строках 8-16-32-64 ...