Назад к вопросам
Middle
104
questionbank
Как сделать так, чтобы при тапе на одну колонку другие не подсвечивались?
Sobes Copilot
Получайте ответы в реальном времени
Ответ от нейросети
sobes.tech AI
Можно создать кастомный UITableViewCell и переопределить методы для управления состоянием выделения.
Вот пример:
import UIKit
class CustomCell: UITableViewCell {
override func setSelected(_ selected: Bool, animated: Bool) {
// Не вызываем super.setSelected
// Управляем внешним видом самостоятельно, если это необходимо
}
override func setHighlighted изHighlightted: Bool, animated: Bool) {
// Не вызываем super.setHighlighted
// Управляем внешним видом самостоятельно, если это необходимо
}
}
В tableView(_:cellForRowAt:) нужно использовать этот кастомный класс:
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
guard let cell = tableView.dequeueReusableCell(withIdentifier: "CustomCell", for: indexPath) as? CustomCell else {
fatalError("The dequeued cell is not an instance of CustomCell.")
}
// Настройка ячейки
return cell
}
Также можно установить UITableViewCell.selectionStyle в .none:
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "CellIdentifier", for: indexPath)
cell.selectionStyle = .none // Отключает стандартную подсветку при тапе
// Настройка ячейки
return cell
}