Reputation: 8138
I have a UIViewController which has a UITableView as a child besides other elements. I want to add editing support on that tableView with this simple line:
self.navigationItem.rightBarButtonItem = self.editButtonItem;
It works if I set this on UITableViewController view type, but obviously that does not work on tableView's that are subviews. Actually it shows the editing button but the edit action is not triggered.
Anyway if there is no elegant solution for that I will simply implement custom editing button.
Thanks!
Upvotes: 2
Views: 4431
Reputation: 1354
You need to implement setEditing:animated yourself:
- (void)setEditing:(BOOL)editing animated:(BOOL)animated
{
[self.tableView setEditing:editing animated:animated];
[super setEditing:editing animated:animated];
}
Upvotes: 2
Reputation: 81
- (void)viewDidLoad
{
[super viewDidLoad];
self.title = @"My View Controller";
self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemEdit target:self action:@selector(editButtonSelected:)] autorelease];
}
- (void) editButtonSelected: (id) sender
{
if (tableView1.editing) {
self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemEdit target:self action:@selector(editButtonSelected:)] autorelease];
[self.tableView1 setEditing:NO animated:YES];
} else {
self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(editButtonSelected:)] autorelease];
[self.tableView1 setEditing:YES animated:YES];
}
}
Upvotes: 3
Reputation: 8138
I've just found a solution. Replacing self.editButtonItem
with self.myTableViewController.editButtonItem
like that:
self.navigationItem.rightBarButtonItem = self.myTableViewController.editButtonItem;
It works like a charm. Could it be more simple? :)
Upvotes: 1