zdestiny
zdestiny

Reputation: 542

Disabling only left swipe on UITableViewCell.

My main view controller includes a table view and also a separate view on the right that folds in when the user pans left.

I have setup a PanGestureRecogniser on this controller so that the user can use it to switch between the two views. It works fine except for one issue.

When there are only one or two cells, the user needs to pan using the empty area at the bottom not covered by cells. When there are cells that cover the entire view, or when the user pans left, the cell's swipe to delete function gets activated, since a pan gesture always fires a swipe gesture.

I want to keep the swipe-to-delete feature, but ONLY when a user swipes right on a cell.

Any left swipes/pans should always unfold the second view on the right. I'm using a custom UITableViewCell subclass. Is there any way to disable ONLY the left swipe to enter the delete mode?

Upvotes: 1

Views: 940

Answers (1)

iOSProgrammingIsFun
iOSProgrammingIsFun

Reputation: 1458

This is entirely possible.

Here's the code. Add the same to your - (void) viewDidLoad method:

UISwipeGestureRecognizer * newSwipeGR = [[UISwipeGestureRecognizer alloc] initWithTarget:nil action:nil];
newSwipeGR.direction = UISwipeGestureRecognizerDirectionLeft;
newSwipeGR.numberOfTouchesRequired = 1;
[self.myTableView addGestureRecognizer:newSwipeGR];

Still enable the deletion mode as normal, but you're now find that the delete swipe only works in one direction.

Upvotes: 1

Related Questions