Middle
Kako učiniti da kada dodirnete jednu kolonu, ostale se ne ističu?
sobes.tech АИ
Одговор од АИ
Možete kreirati prilagođenu UITableViewCell i prepisati metode za upravljanje stanjem selekcije.
Evo primera:
import UIKit
class CustomCell: UITableViewCell {
override func setSelected(_ selected: Bool, animated: Bool) {
// Ne pozivajte super.setSelected
// Samostalno upravljajte izgledom, ako je potrebno
}
override func setHighlighted(_ highlighted: Bool, animated: Bool) {
// Ne pozivajte super.setHighlighted
// Samostalno upravljajte izgledom, ako je potrebno
}
}
U tableView(_:cellForRowAt:) treba koristiti ovu prilagođenu klasu:
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
guard let cell = tableView.dequeueReusableCell(withIdentifier: "CustomCell", for: indexPath) as? CustomCell else {
fatalError("Ćelija u redu nije instanca CustomCell.")
}
// Podešavanje ćelije
return cell
}
Takođe, možete postaviti UITableViewCell.selectionStyle na .none:
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "CellIdentifier", for: indexPath)
cell.selectionStyle = .none // Isključuje standardno isticanje na tap
// Podešavanje ćelije
return cell
}