Middle
Kuidas teha nii, et kui puudutate ühte veergu, teised ei oleks esile tõstetud?
sobes.tech AI
Vastus AI-lt
Saate luua kohandatud UITableViewCell ja üle kirjutada meetodid valiku oleku haldamiseks.
Siin on näide:
import UIKit
class CustomCell: UITableViewCell {
override func setSelected(_ selected: Bool, animated: Bool) {
// Ära kutsu super.setSelected
// Kui vaja, hallake välimust ise
}
override func setHighlighted(_ highlighted: Bool, animated: Bool) {
// Ära kutsu super.setHighlighted
// Kui vaja, hallake välimust ise
}
}
tableView(_:cellForRowAt:) funktsioonis tuleb kasutada seda kohandatud klassi:
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
guard let cell = tableView.dequeueReusableCell(withIdentifier: "CustomCell", for: indexPath) as? CustomCell else {
fatalError("Reast ei leidu CustomCell eksemplar.")
}
// Lahtri seadistamine
return cell
}
Samuti saate määrata UITableViewCell.selectionStyle väärtuseks .none:
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "CellIdentifier", for: indexPath)
cell.selectionStyle = .none // Keelab standardse esiletõstmise
// Lahtri seadistamine
return cell
}