I'm trying to use an extra row at the bottom of my UITableView which would be used to insert a record. This works fine, but I'm having trouble getting it to animate properly. Either the extra row is shown properly and I get no animation (by using [self.tableView reloadData] in the setEditing: method. Or, I get animation and no extra row by not using reloadData. I know that I'm probably not showing the extra row properly (returning one more row in my numberOfRowsInSection method, and using reloadData to force a refresh.).
I know there must be a right way to do this, but I haven't seen any examples.
- (void)setEditing:(BOOL)editing animated:(BOOL)animated {
[super setEditing:editing animated:animated];
[self.tableView setEditing:editing animated:animated];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
id <NSFetchedResultsSectionInfo> sectionInfo = [[fetchedResultsController sections] objectAtIndex:section];
if (self.editing == YES) {
return [sectionInfo numberOfObjects] + 1;
}
return [sectionInfo numberOfObjects];
}
- (void)configureCell:(UITableViewCell *)cell atIndexPath:(NSIndexPath *)indexPath {
if (indexPath.row + 1 > [fetchedResultsController.fetchedObjects count]) {
cell.textLabel.text = @"Add New Row...";
[cell setSelectionStyle:UITableViewCellSelectionStyleNone];
} else {
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
MyManagedObject *aManagedObject = [fetchedResultsController.fetchedObjects objectAtIndex:indexPath.row];
cell.textLabel.text = aManagedObject.planName;
}
}