Sobes.tech
Middle

Kā padarīt, lai, pieskaroties vienai kolonnai, citas netiktu izceltas?

sobes.tech AI

Atbilde no AI

Jūs varat izveidot pielāgotu UITableViewCell un pārrakstīt metodes, lai pārvaldītu atlases stāvokli.

Šeit ir piemērs:

import UIKit

class CustomCell: UITableViewCell {

    override func setSelected(_ selected: Bool, animated: Bool) {
        // Neizsauciet super.setSelected
        // Ja nepieciešams, pārvaldiet izskatu pats
    }

    override func setHighlighted(_ highlighted: Bool, animated: Bool) {
        // Neizsauciet super.setHighlighted
        // Ja nepieciešams, pārvaldiet izskatu pats
    }
}

tableView(_:cellForRowAt:) funkcijā jāizmanto šī pielāgotā klase:

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    guard let cell = tableView.dequeueReusableCell(withIdentifier: "CustomCell", for: indexPath) as? CustomCell else {
        fatalError("Rindā nav instances no CustomCell.")
    }
    // Šūnas konfigurācija
    return cell
}

Tāpat var iestatīt UITableViewCell.selectionStyle uz .none:

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCell(withIdentifier: "CellIdentifier", for: indexPath)
    cell.selectionStyle = .none // Izslēdz standarta izcelšanu
    // Šūnas konfigurācija
    return cell
}