Neelesh
Neelesh

Reputation: 3693

Left swipe for delete and edit,delete

I am not able to find a way around this. Is it possible to have delete option using left swipe and also using edit and delete.

I have edit button on the left of the navigation bar.

self.navigationItem.leftBarButtonItem = self.editButtonItem;

and commitEditingStyle method as below

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {

    if (editingStyle == UITableViewCellEditingStyleDelete) {
//delete code here
    }   
    else if (editingStyle == UITableViewCellEditingStyleInsert) {
    // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view.
    }   

}

After using this, the left swipe is not being detected at all. the only way to delete seems to be by going to the edit mode and deleting from there. help would be appreciated.

I am a newbie so please go easy with me :)

Upvotes: 0

Views: 2708

Answers (3)

Anand
Anand

Reputation: 1973

you mean swiping on cell you need delete option.

If so you can try this code:

- (UITableViewCellEditingStyle)tableView:(UITableView *)aTableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {

    return UITableViewCellEditingStyleDelete;

}

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {

    //perform delete operation

}

Upvotes: 3

Jordan
Jordan

Reputation: 21760

Make sure you have all of the delegates implemented below

tableView:commitEditingStyle:forRowAtIndexPath:
tableView:canEditRowAtIndexPath:
tableView:editingStyleForRowAtIndexPath

:

Upvotes: 1

Ravin
Ravin

Reputation: 8564

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {

    if (editingStyle == UITableViewCellEditingStyleDelete) {
//delete code here
    }   
    else if (editingStyle == UITableViewCellEditingStyleInsert) {
    // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view.
    }  

once you write above method in your delegate you will be able to use swipe gestures.... and in this method you will handle the subsequent actions that you want to perform.

thanks.....

Upvotes: 0

Related Questions