Left swipe for delete and edit,delete
I am not able to find a way around thi开发者_高级运维s. 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 :)
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
}
Make sure you have all of the delegates implemented below
tableView:commitEditingStyle:forRowAtIndexPath:
tableView:canEditRowAtIndexPath:
tableView:editingStyleForRowAtIndexPath
:
- (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.....
精彩评论