I need activate did select row at after long press at tableview, how i can do this?

54 Views Asked by At

I have i @objc func longpress, and didSelectRowAt in UITableViewDelegate, i need activate did select row at after i do long press on table cell, this what i try to code:

 @objc func longpress(sender: UILongPressGestureRecognizer) {

        if sender.state == UIGestureRecognizer.State.began {
            let touchPoint = sender.location(in: usersTableView)
            if let indexPath = usersTableView.indexPathForRow(at: touchPoint) {
                UINotificationFeedbackGenerator().notificationOccurred(.success)
                userLabel.text = "Select"
                usersNumber.text = "1"
                plusButton.backgroundColor = UIColor(named: "Orange")
                plusButton.setImage(UIImage(named: "bin"), for: .normal)
                print("Long press Pressed")
            }
        }
    }
extension UsersController: UITableViewDelegate {
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        if(tapCount == 1 && tapTimer != nil && tappedRow == indexPath.row){
        debugPrint("double tap - Put your double tap code here")
   
            
            usersTableView.reloadData()
            tapTimer?.invalidate()
            tapTimer = nil
            tapCount = 0
        }
        else if(tapCount == 0){
            debugPrint("This is the first tap. If there is no tap till tapTimer is fired, it is a single tap")
            tapCount = tapCount + 1;
            tappedRow = indexPath.row;
            tapTimer = Timer.scheduledTimer(timeInterval: 0.4, target: self, selector: #selector (tapTimerFired), userInfo: nil, repeats: false)
        }
        else if(tappedRow != indexPath.row){
            //debugPrint("Tap on new row")
            tapCount = 0;
            if(tapTimer != nil){
                tapTimer?.invalidate()
                tapTimer = nil
                    }
                }
            }
        }
0

There are 0 best solutions below