Editable UITableView
I'm trying to set up a UITableView that I can edit. I have the following methods implemented:
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
but I'm not sure how to link editing to an edit button in my UINavigationBar. Here is my button item:
UIBarButtonItem * leftButton = [[UIBarButtonItem alloc] initWithTitle:@"Edit开发者_StackOverflow社区"
style:UIBarButtonSystemItemEdit
target:nil
action:@selector(editButtonSelected:)];
How do I get this working?
I have had a lot of success just using the standard edit button:
self.navigationItem.leftBarButtonItem = self.editButtonItem;
The problem with your code is that you didn't set a target. If the editButtonSelected: selector is in the view controller where you are setting this up, use "self" like this:
UIBarButtonItem *leftButton = [[UIBarButtonItem alloc] initWithTitle:@"Edit" style:UIBarButtonSystemItemEdit target:self action:@selector(editButtonSelected:)];
精彩评论