Sobes.tech
Middle

Ինչպե՞ս անել, որ երբ սեղմում եք մեկ սյունակի վրա, մյուսները չեղյալ հայտարարվեն։

sobes.tech AI

Պատասխան AI-ից

Դուք կարող եք ստեղծել անհատականացված UITableViewCell և վերագրել մեթոդները ընտրության վիճակը կառավարելու համար:

Ահա օրինակ՝

import UIKit

class CustomCell: UITableViewCell {

    override func setSelected(_ selected: Bool, animated: Bool) {
        // Մի կանչեք super.setSelected
        // Անհատականորեն կառավարեք տեսքը, եթե անհրաժեշտ է
    }

    override func setHighlighted(_ highlighted: Bool, animated: Bool) {
        // Մի կանչեք super.setHighlighted
        // Անհատականորեն կառավարեք տեսքը, եթե անհրաժեշտ է
    }
}

tableView(_:cellForRowAt:)-ում պետք է օգտագործել այս անհատականացված դասը:

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    guard let cell = tableView.dequeueReusableCell(withIdentifier: "CustomCell", for: indexPath) as? CustomCell else {
        fatalError("Տողում գտնվող բջիջը չի հանդիսանում CustomCell-ի օրինակ:")
    }
    // Բջջի կարգավորում
    return cell
}

Կարող եք նաև սահմանել UITableViewCell.selectionStyle.none:

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCell(withIdentifier: "CellIdentifier", for: indexPath)
    cell.selectionStyle = .none // Դադարեցնում է ստանդարտ ընդգծումը սեղմելու ժամանակ
    // Բջջի կարգավորում
    return cell
}