Middle
Como fazer para que ao tocar numa coluna, as outras não sejam destacadas?
sobes.tech IA
Resposta da IA
É possível criar uma UITableViewCell personalizada e substituir os métodos para gerir o estado de seleção.
Aqui está um exemplo:
import UIKit
class CustomCell: UITableViewCell {
override func setSelected(_ selected: Bool, animated: Bool) {
// Não chamamos super.setSelected
// Gerimos a aparência por nossa conta, se necessário
}
override func setHighlighted(_ highlighted: Bool, animated: Bool) {
// Não chamamos super.setHighlighted
// Gerimos a aparência por nossa conta, se necessário
}
}
Na função tableView(_:cellForRowAt:), deve usar esta classe personalizada:
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
guard let cell = tableView.dequeueReusableCell(withIdentifier: "CustomCell", for: indexPath) as? CustomCell else {
fatalError("A célula em fila não é uma instância de CustomCell.")
}
// Configuração da célula
return cell
}
Também pode definir UITableViewCell.selectionStyle para .none:
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "CellIdentifier", for: indexPath)
cell.selectionStyle = .none // Desativa o realce padrão ao tocar
// Configuração da célula
return cell
}