UITableView editing not working
I have a button (a UINavigationBarItem) used for editing my UITableView, which only allows deletions. So when I press delete, the little red line comes up next to each cell, and I can delete each row.
When the button is pressed, the following function is called:
-(void)editButtonSelected:(id)sender {
if(self.editing)
NSLog(@"self.editing = true");
else
NSLog(@"self.editing = false");
if(self.editing) {
[super setEditing:NO animated:NO];
[tableView setEditing:NO animated:NO];
[tableView reloadData];
[leftButton setTitle:@"Delete"];
[leftButton setStyle:UIBarButtonItemStylePlain];
self.editing = false;
}
else {
[super setEditing:YES animated:YES];
[tableView setEditing:YES animated:YES];
[tableView reloadData];
[leftButton setTitle:@"Done"];
[leftButton setStyle:UIBarButtonItemStyleDone];
self.editing = true;
}
}
And it works fine. But only for a while. As soon as I introduce a new UIViewController, and then dismiss that controller, this delete function doesn't work on this main screen I have. It works fine until a new UIViewController is put on top. The button 开发者_开发知识库itself works fine, and the value of self.editing does get toggled between true and false correctly, but the little red lines do not show up. Why could this be happening?
I would guess that the target on your UINavigationBarItem is still set to the first view controller, not the subsequent view controllers that get pushed on the stack.
精彩评论