Middle
Hoe zorg je ervoor dat bij het tikken op één kolom, de andere niet worden gemarkeerd?
sobes.tech AI
Antwoord van AI
Je kunt een aangepaste UITableViewCell maken en de methoden overschrijven om de selectiestatus te beheren.
Hier is een voorbeeld:
import UIKit
class CustomCell: UITableViewCell {
override func setSelected(_ selected: Bool, animated: Bool) {
// Roep super.setSelected niet aan
// Beheer het uiterlijk zelf indien nodig
}
override func setHighlighted(_ highlighted: Bool, animated: Bool) {
// Roep super.setHighlighted niet aan
// Beheer het uiterlijk zelf indien nodig
}
}
In tableView(_:cellForRowAt:) moet je deze aangepaste klasse gebruiken:
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
guard let cell = tableView.dequeueReusableCell(withIdentifier: "CustomCell", for: indexPath) as? CustomCell else {
fatalError("De gedequeuede cel is geen instantie van CustomCell.")
}
// Configuratie van de cel
return cell
}
Je kunt ook UITableViewCell.selectionStyle instellen op .none:
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "CellIdentifier", for: indexPath)
cell.selectionStyle = .none // Schakelt de standaard highlight uit bij tikken
// Configuratie van de cel
return cell
}