Search code examples
iosipadios6

Enable/Disable the swipe to delete functionality on UITableViewCell dynamically


I have added a gesture recognizer on the UITableViewCell to drag the cell to other view within the same view controller. For this I have added a long press gesture recognizer to the cell.

But I also need swipe to delete functionality when we are not dragging the cell. But when I start the drag and move in one direction(right or left) then the Cell fires the call for swipe-to-delete(which is default) as well.

I need to stop this call at this moment.Reloading the tableView is not an option as After reloading I would loose the selected cell for dragging.


Solution

  • A few guesses if any of them works for you-

    1. Check the tableView:shouldIndentWhileEditingRowAtIndexPath: delegate method.
    2. Turn off the editing mode put swipe gesture and long press gesture directly along with the function to handle multiple gestures(just to be precise).

    Now, what you can do here is that increase the long press time or just add the function to detect multiple gestures.

    - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
    { 
        return YES; 
    }