Deselecting custom UITableViewCell that was selected by UILongPressGestureRecognizer

Question

I have a custom UITableViewCell class My custom UITableViewCell If user wants to select first cell, UILongPressGestureRecognizer called after that cell selected and when user had already chosen minimum one cell, then he could choose another cells without long pressing on it, just calling function didSelectRow. I tried do it by myself, but I couldn't. It was actually working but first user that was selected by long press, can't be deselected. I searched and found that I should cancel touches in view, but it didn't work for me. So cells that are called with didSelectRow are working fine, I can select and deselect, except one cell that was selected by UILongPressGesture.

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {

    if let cell = tableView.cellForRow(at: indexPath) as? ContactCell {

        if inSelectionMode {
            selectUser(cell: cell, indexPath: indexPath)
        } else {
            if let cameraViewControl = presentingViewController as? CameraViewController {
                cameraViewControl.smallView()
            }

            dismiss(animated: true, completion: nil)
        }

    }


}

func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
    if tableView == contactTblView {

        let tap = UILongPressGestureRecognizer(target: self, action: #selector(longTapSelectUser(_:)))
        tap.cancelsTouchesInView = false
        cell.addGestureRecognizer(tap)

    }
}

func longTapSelectUser(_ gesture: UILongPressGestureRecognizer) {
    if let cell = gesture.view as? ContactCell, let indexPath = self.contactTblView.indexPath(for: cell) {
        inSelectionMode = true
        selectUser(cell: cell, indexPath: indexPath)
    }
}

Show source
| xcode   | swift   | ios   | iphone   | ios10   2017-08-17 13:08 0 Answers

Answers to Deselecting custom UITableViewCell that was selected by UILongPressGestureRecognizer ( 0 )

Leave a reply to - Deselecting custom UITableViewCell that was selected by UILongPressGestureRecognizer

◀ Go back