1

I want to enable editing for a single cell in a Table View at the selected index of a long press event, everything works except it enables editing for the entire table. How can I enable editing only on the cell that is selected?

-(void)handleLongPress:(UILongPressGestureRecognizer *)gestureRecognizer {

    CGPoint p = [gestureRecognizer locationInView:self.savedPropertyTableView];

    NSIndexPath *indexPath = [self.savedPropertyTableView indexPathForRowAtPoint:p];
            if (indexPath == nil) {
            [self setEditing:YES animated:YES];
            NSLog(@"long press on table view but not on a row");
        }

        else {
            [self setEditing:YES animated:YES];
            NSLog(@"long press on table view at row %d", indexPath.row);
        } 
    }
Dayn Goodbrand
  • 611
  • 7
  • 16

2 Answers2

0

Instead of whole table make that single cell editable :

UITableViewCell *newCell = [yourTable cellForRowAtIndexPath:indexPath];

[newCell setEditing:YES animated:YES];
Anusha Kottiyal
  • 3,855
  • 3
  • 28
  • 45
  • Unfortunately this doesnt work, maybe something to do with the red `-` that comes up not letting it be on a single cell. Either way swipe works exactly as intended. Thanks for the help – Dayn Goodbrand Dec 14 '12 at 06:10
0

Not a exact solution but same result, i have created a swipe gesture instead and that works like i was hoping (delete a single cell)

In the Table View Cell:

UISwipeGestureRecognizer *sgdr = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSlideRight:)];
[sgdr setDirection:UISwipeGestureRecognizerDirectionRight];
[self.savedPropertyTableView addGestureRecognizer:lpgr];

Then created method:

-(void)handleSlideRight:(UISwipeGestureRecognizer *)gestureRecognizer {
    CGPoint p = [gestureRecognizer locationInView:self.savedPropertyTableView];

    NSIndexPath *indexPath = [self.savedPropertyTableView indexPathForRowAtPoint:p];
    if (indexPath == nil)
    {
        [self setEditing:YES animated:YES];
        NSLog(@"slide on table view but not on a row");
    }

    else
    {
        [self setEditing:YES animated:YES];
        NSLog(@"slide on table view at row %d", indexPath.row);
    }
}
Dayn Goodbrand
  • 611
  • 7
  • 16