Middle
Kaip padaryti, kad paspaudus vieną stulpelį, kitos nebūtų pažymėtos?
sobes.tech AI
Atsakymas iš AI
Jūs galite sukurti individualią UITableViewCell ir perrašyti metodus, skirtus valdyti pasirinkimo būseną.
Štai pavyzdys:
import UIKit
class CustomCell: UITableViewCell {
override func setSelected(_ selected: Bool, animated: Bool) {
// Nenaudokite super.setSelected
// Jei reikia, patys valdykite išvaizdą
}
override func setHighlighted(_ highlighted: Bool, animated: Bool) {
// Nenaudokite super.setHighlighted
// Jei reikia, patys valdykite išvaizdą
}
}
tableView(_:cellForRowAt:) funkcijoje turite naudoti šį individualų klasės pavyzdį:
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
guard let cell = tableView.dequeueReusableCell(withIdentifier: "CustomCell", for: indexPath) as? CustomCell else {
fatalError("Eilutės eilėje nėra CustomCell pavyzdžio.")
}
// Ląstelės konfigūracija
return cell
}
Taip pat galite nustatyti UITableViewCell.selectionStyle į .none:
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "CellIdentifier", for: indexPath)
cell.selectionStyle = .none // Išjungia standartinį pažymėjimą
// Ląstelės konfigūracija
return cell
}