I have a UIViewController class, with a tableView. In viewDidLoad:
UIBarButtonItem *editIcon = [[[UIBarButtonItem alloc]
initWithBarButtonSystemItem: UIBarButton
Why not use -editButtonItem
of UIViewController directly ? And override -setEditing:animated:
method.
// Assign the system's edit button,
// it will change style when different edit status.
self.navigationItem.rightBarButtonItem = self.editButtonItem;
// The editButtonItem will invoke this method.
- (void)setEditing:(BOOL)editing animated:(BOOL)animated {
[super setEditing:editing animated:animated];
if (editing) {
// Execute tasks for editing status
} else {
// Execute tasks for non-editing status.
}
}