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
}