0

I have a custom swipe recognition class from this example: How to detect a swipe-to-delete gesture in a customized UITableviewCell?

    - (void)cellSwiped:(UIGestureRecognizer *)gestureRecognizer {
    if (gestureRecognizer.state == UIGestureRecognizerStateEnded) {
        UITableViewCell *cell = (UITableViewCell *)gestureRecognizer.view;
        NSIndexPath* indexPath = [self.tableView indexPathForCell:cell];
    }
}

Now I would like to select that single row at the indexPath and enable edit mode for it, could someone show me how it can be done?

Community
  • 1
  • 1

3 Answers3

2

Cache the row you want somewhere and in your implementation of - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath just only return YES for the row you want to be editable. Then enter edit mode by sending [tableView setEditing:YES animated:YES];.

i_am_jorf
  • 53,608
  • 15
  • 131
  • 222
  • I understand what you are trying to say, but I'm quite new to the iOS programming yet and I don't exactly understand what have to be done. I did something like this and it doesn't seem to work. if ([notifTable cellForRowAtIndexPath:indexPath]) { [[notifTable cellForRowAtIndexPath:indexPath]setEditing:YES animated:YES]; return YES; – user2180859 Mar 18 '13 at 04:17
0

You could have a variable in your class that is an NSIndexPath *index then have

-(BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    return indexPath == self.index;
}

And set index to whatever cell you want to be able to edit, then call tableView setEditing:YES animated:YES/NO whenever you want to edit that cell.

Jsdodgers
  • 5,253
  • 2
  • 20
  • 36
0

Try like this,

In your tableView didSelectRowAtIndex delegate method call the editingStyleForRowAtIndexPath method,

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
 [yourTableView.delegate tableView:tableView editingStyleForRowAtIndexPath:indexPath];
}

In editingStyleForRowAtIndexPath method,

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


  return UITableViewCellEditingStyleDelete;

  }


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



}
Venk
  • 5,949
  • 9
  • 41
  • 52