0

I am having a table view with some datas. While on left swipe of cell i want 'Delete' and 'Edit'. I got 'Delete' by using the below code. Please help me to solve this..

- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.section == 0) {
        return NO;

    }
    return YES;
}

  - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        [self.circleGroupArray removeObjectAtIndex:indexPath.row];

        [_myCircleTableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
    }
}
sruthy
  • 13
  • 4
  • With default methods, it won't be available, you can go with library like : https://github.com/MortimerGoro/MGSwipeTableCell – Viral Savaj Nov 21 '18 at 09:43
  • 1
    Possible duplicate of [Custom edit view in UITableViewCell while swipe left. Objective-C or Swift](https://stackoverflow.com/questions/19164188/custom-edit-view-in-uitableviewcell-while-swipe-left-objective-c-or-swift) – Teja Nandamuri Nov 21 '18 at 13:44

1 Answers1

0

Use this method in your class, If you want more actions you can create more UITableViewRowActions and add them to array.

 -(NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath {

   UITableViewRowAction *editAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleNormal title:@"Clona" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath){
      //add edit action here
   }];
   editAction.backgroundColor = [UIColor blueColor];

   UITableViewRowAction *deleteAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleNormal title:@"Delete"  handler:^(UITableViewRowAction *action, NSIndexPath *indexPath){
      //add delete action here
   }];
   deleteAction.backgroundColor = [UIColor redColor];
   return @[deleteAction,editAction];
}
Dinesh Gurrapu
  • 158
  • 1
  • 1
  • 11