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
}