I have an app set up to have a tableview, whic开发者_JAVA百科h 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];
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.
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.
精彩评论