2

I have a UITableView with some custom cells in it. In these custom cells I defined a UILongPressGestureRecognizer that triggers the edit mode of this table. So when someone presses and holds a cell for like 1.5 sec, the table goes into edit mode.

UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(startEditMode:)];

Which triggers:

- (void)startEditMode:(UISwipeGestureRecognizer *)recognizer {

    if (self.allowEdit) {
        UITableView *table = (UITableView *)self.superview;
        [table setEditing:YES animated:YES];
    }

}

But what I want to do is detect when the table goes into edit mode because I need to show/hide some additional buttons in this case. But for some reason in my viewcontroller this is never executed:

- (void)setEditing:(BOOL)editing animated:(BOOL)animated {
    NSLog(@"SET EDITING");
    [super setEditing:editing animated:animated];
}

Any suggestion why? Is this just being called when using a proper Edit Button as provided by default in the UINavigationController?

Or how can I detect when my UITableView goes into Edit Mode?

Jules
  • 7,148
  • 6
  • 26
  • 50

2 Answers2

4

You're sending the message (setEditing) to the table view, you should be sending it to the view controller (presumably a UITableViewController subclass?). It will then take care of the table view for you.

jrturton
  • 118,105
  • 32
  • 252
  • 268
1

Ok so in case someone else walks into this thread with the same problem, I will show you how I solved this.

In my custom UITableViewCell I have this method now:

- (void)startEditMode:(UISwipeGestureRecognizer *)recognizer {

    if (self.allowEdit) {
        UITableView *table = (UITableView *)self.superview;
        UITableViewController *control = (UITableViewController *)table.dataSource;
        [control setEditing:YES animated:YES];
    }

}
Jules
  • 7,148
  • 6
  • 26
  • 50