Question

I don't want the swipe to delete the row but do something else. What code do I need to add to the UITableViewController to have that happen

Was it helpful?

Solution

In looking at the docs, you might be able to code around the default behavior by not enabling the swipe to delete stuff, and looking at the example code mentioned in the UISwipeGestureRecognizer class.

I don't know what you application is, but one thing I feel compelled to mention is that it'd be considered a design flaw to have an editable list where swipe didn't do the delete behavior. This would break the principle of least astonishment, and confuse users.

That said, you might have a great use, I don't know. Best of luck.

OTHER TIPS

You have to implement a UISwipeGestureRecognizer in your viewDidLoad. For example a right swipe gesture can be implemented like so:

- (void)viewDidLoad
{ 
    [super viewDidLoad];

    // more stuff

    // Recognizing right swiping gestures
    UISwipeGestureRecognizer *rightSwipeGestureRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(rightSwipe:)];
    // right swipe direction is default
    rightSwipeGestureRecognizer.direction = UISwipeGestureRecognizerDirectionRight;
    [self.tableView addGestureRecognizer:rightSwipeGestureRecognizer];
    [rightSwipeGestureRecognizer release];
}

- (void)rightSwipe:(id)sender
{
    // Do something
}

As always, more information available in Apple's most excellent documentation.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top