views:

32

answers:

2

I have an app set up to have a tableview, which allows the user to add and delete cells (which are events). Adding and deleting DOES work, however when I delete a cell (by entering edit mode), I can click the (-) button to delete, then I hit the delete button, however the delete button stays highlighted and the cell does not disappear until I hit the "Done" button which exits edit mode. Is this an issue anyone has seen? If so, is there a solution? Thanks

EDIT:

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

NSLog(@"Delete");

[eventList removeObjectAtIndex:indexPath.row];
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject: indexPath] withRowAnimation:YES];
[tableView reloadData];
+1  A: 

I suggest removing the call to reloadData in commitEditingStyle. The deleteRowsAtIndexPaths already takes care of redrawing the table view.

The best place to start looking for written sources is the documentation.
See "An Example of Deleting a Table-View Row" on this page.

Also note that in deleteRowsAtIndexPaths, withRowAnimation does NOT take a BOOL parameter. Instead of YES, it should be a UITableViewRowAnimation enum value like UITableViewRowAnimationFade.

aBitObvious
I read the documentation and I feel like my code (now that I did what you said) is fine. I dont know if this helps but I put up a little video of what is happening exactly: http://www.youtube.com/watch?v=eyAHdodUv-c
Inanepenguin
Ok, is the video before or after removing the reloadData? Not clear from your comment whether it's fixed or is there still a problem? Note that some or all of the table view's data source and delegate methods will get called when doing deleteRowsAtIndexPaths so make sure all of your underlying data source is updated before calling it. Is eventList the only thing you need to update?
aBitObvious
A: 

You definitely don't need the reloadData after doing the row deletion. If it still doesn't work, you might want to try wrapping the deletion in a beginUpdates and endUpdates. Finally, the withRowAnimation: argument should be one of the UITableViewRowAnimation enums instead of a BOOL.

Daniel Dickison