I have a tableviewController. On the UINavigationBar i will be adding a button called Edit. When the user clicks on it i need all the cells to go for the edit mode, where they could delete records.
I guess the following method does it. Am i correct ? will i get the red circle and the delete button on the cell when i click the edit button?
2.) How can i write the code for the Edit button (UIBarbuttonitem), when the user clicks it to call the following method ?
3.) When we delete the cell, i need to reload the data in the table. I wrote the code for this, is it correct. (I am not in my Mac at the moment)
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle == UITableViewCellEditingStyleDelete) {
// Delete the row from the data source
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
[self.tableView beginUpdates];
[discardedItems addObject:[self.entries objectAtIndex:indexPath.row]];
[self.itemsMutableArray removeObjectsInArray:discardedItems ];
self.entries = [NSArray arrayWithArray:self.itemsMutableArray];
[self.tableView endUpdates];
[self.tableView reloadData];
}
else if (editingStyle == UITableViewCellEditingStyleInsert) {
// Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
}
}
First of all, you need to specify if the rows can be edited. This is done by the following method
return yes if you want all the rows to be editable.
To get the red circles use this,
Perhaps in a method called by the edit button…
(in viewdidload)
and in pressedEdit:
According to the code youve written, i think you should first update the datasource and then remove the cell…