Middle
Bir ustun bosilganda, boshqalar yoritilmasligi uchun qanday qilish mumkin?
sobes.tech AI
AIdan javob
Siz UITableViewCell ning moslashtirilgan versiyasini yaratishingiz va tanlash holatini boshqarish uchun metodlarni qayta yozishingiz mumkin.
Mana bir misol:
import UIKit
class CustomCell: UITableViewCell {
override func setSelected(_ selected: Bool, animated: Bool) {
// super.setSelected ni chaqirmang
// Agar kerak bo'lsa, tashqi ko'rinishni o'zingiz boshqaring
}
override func setHighlighted(_ highlighted: Bool, animated: Bool) {
// super.setHighlighted ni chaqirmang
// Agar kerak bo'lsa, tashqi ko'rinishni o'zingiz boshqaring
}
}
tableView(_:cellForRowAt:) da bu maxsus klassni ishlatishingiz kerak:
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
guard let cell = tableView.dequeueReusableCell(withIdentifier: "CustomCell", for: indexPath) as? CustomCell else {
fatalError("Kuyrukda CustomCell tipidagi instansiya mavjud emas.")
}
// Huja konfiguratsiyasi
return cell
}
Shuningdek, UITableViewCell.selectionStyle ni .none ga o'rnatishingiz mumkin:
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "CellIdentifier", for: indexPath)
cell.selectionStyle = .none // Standart yoritishni o'chiradi
// Huja konfiguratsiyasi
return cell
}