The accepted answer in the link you've provided is for both swipes directions.
Notice that gestureRecognizer.direction returns YES both for UISwipeGestureRecognizerDirectionLeft and UISwipeGestureRecognizerDirectionRight.
You'll just need to modify a couple of things:
Change the selector that get's called upon swiping, so it'll call your method, instead of the one in the post's example,
And change the direction of the swipe to be from left to right only, and not for both directions as it currently is, since, as I understand, you are trying to set a one-direction swipe.
So your code should look like this:
// In cellForRowAtIndexPath:, where you create your custom cell
cell.tableView=tableView;
cell.indexPath=indexPath;
UISwipeGestureRecognizer *swipeGestureRecognizer=[[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(YOUR_METHOD_GOES_HERE)];
[cell addGestureRecognizer:swipeGestureRecognizer];
.
-(BOOL) gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {
if([[gestureRecognizer view] isKindOfClass:[UITableViewCell class]] && ((UISwipeGestureRecognizer*)gestureRecognizer.direction==UISwipeGestureRecognizerDirectionRight)
return YES;
}
Note that you could also use the answer below the accepted answer, and just modify the gesture recogniser direction property to be UISwipeGestureRecognizerDirectionRight, instead of the current direction in the example, which is UISwipeGestureRecognizerDirectionLeft.
If you choose to implement this, your viewController must implement the gesture recogniser delegate, and your code should look like this:
// Call this method in viewDidLoad
- (void)setUpLeftSwipe {
UISwipeGestureRecognizer *recognizer;
recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self
action:@selector(swipeRightt:)];
[recognizer setDirection:UISwipeGestureRecognizerDirectionRight];
[self.tableView addGestureRecognizer:recognizer];
recognizer.delegate = self;
}
- (void)swipeRight:(UISwipeGestureRecognizer *)gestureRecognizer {
CGPoint location = [gestureRecognizer locationInView:self.tableView];
NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:location];
... do something with cell now that i have the indexpath, maybe save the world? ...
}
Note- if I'm not mistaken, you'll need to create the cell swiping animation yourself, as, I believe, Xcode's default cell animation is only when swiping left.
Credit goes to MadhavanRP and Julian from the link you've provided. I just modified their answers to suite better to your needs.
I haven't tried and implemented this myself though.