26.4 C
New York
Thursday, September 12, 2024

ios – Methods to not reply to didSelectRowAt when including single and double click on UITapGestureRecognizer on UITableViewCell


I added UITapGestureRecognizer for single and double clicks on UITableViewCell, and let the one click on gesture be responded to when the double click on gesture fails, however I do not need the tableView’s didSelected to be responded to. Is there any option to deal with this within the TableViewCell class?

class ViewController: UIViewController {
    
    let dataSource = ["1", "2", "3", "4", "5", "6", "7", "8", "9"]
    
    lazy var tableView: UITableView = {
        let view = UITableView(body: CGRectZero)
        view.dataSource = self
        view.delegate = self
        view.register(TableViewCell.self, forCellReuseIdentifier: TableViewCell.description())
        return view
    }()

    override func viewDidLoad() {
        tremendous.viewDidLoad()
        // Do any extra setup after loading the view.
        self.view.addSubview(tableView);
        tableView.body = CGRect(x: 0, y: 0, width: UIScreen.essential.bounds.width, peak: UIScreen.essential.bounds.peak)
    }
}

extension ViewController: UITableViewDataSource, UITableViewDelegate {
    func tableView(_ tableView: UITableView, numberOfRowsInSection part: Int) -> Int {
        dataSource.rely
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        if let cell = tableView.dequeueReusableCell(withIdentifier: TableViewCell.description(), for: indexPath) as? TableViewCell {
            return cell;
        }
        return UITableViewCell()
    }
    
    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        40
    }
    
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
         
    }
}

class TableViewCell: UITableViewCell {
    
    override init(model: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        tremendous.init(model: model, reuseIdentifier: reuseIdentifier)
        let singleTapGesture = UITapGestureRecognizer(goal: self, motion: #selector(faucet))
        singleTapGesture.cancelsTouchesInView = false;
        addGestureRecognizer(singleTapGesture)
        
        let doubleTapGesture = UITapGestureRecognizer(goal: self, motion: #selector(doubleTap))
        doubleTapGesture.numberOfTapsRequired = 2
        addGestureRecognizer(doubleTapGesture)
       
        singleTapGesture.require(toFail: doubleTapGesture)
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been carried out")
    }
    
    @objc func faucet() {
        
    }
    
    @objc func doubleTap() {
        
    }
}

I need solely faucet and doubleTap to be known as in case of single and double click on, however didSelectRowAt will not be known as

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles