当UITableView处于编辑模式时显示UIButton

时间:2012-11-14 20:24:11

标签: iphone objective-c uitableview uibutton

当UITableView处于编辑模式时,我正在尝试显示UIButton:

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {

    if (editingStyle == UITableViewCellEditingStyleDelete) {
    NSLog(@"deleting :%i", indexPath.row);

        // Delete the managed object for the given index path
        NSManagedObjectContext *context = [fetchedResultsController managedObjectContext];
        [context deleteObject:[fetchedResultsController objectAtIndexPath:indexPath]];

        self.buttonAdd.hidden = FALSE;

        // Save the context.
        NSError *error = nil;
        if (![context save:&error]) {
            NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
            exit(-1);
        }
    }
[self.table reloadData];
}

但这不起作用,你有什么想法吗?

1 个答案:

答案 0 :(得分:1)

- (void)setEditing:(BOOL)editing animated:(BOOL)animated
{
    // Make sure you call super first
    [super setEditing:editing animated:animated];

    if (editing)
    {
         do your code
      //  self.editButtonItem.title = NSLocalizedString(@"Cancel", @"Cancel");
    }
    else
    {
              do your code
       // self.editButtonItem.title = NSLocalizedString(@"Edit", @"Edit");
    }
}