I overrode the method:
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView
editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
to make a plus button appear next to a cell. After the user edits the cell's contents, I want to change it from a plus button to a minus button. The logic is already written in this method. The problem is that even though this method is called and it's returning the correct value it doesn't update the button.
Using:
[myViewCell setNeedsLayout];
... doesn't cause [myTableView tableView:editngStyleForRowatIndexPath:]
to be run.
Calling
[tableView reloadRowsAtIndexPaths: ... withRowAnimation:UITableViewRowAnimationNone];
... does something weird... it causes [myTableView tableView:editngStyleForRowatIndexPath:]
to be called on all rows EXCEPT the one I send in the reloadRowsAtIndexPaths
parameter.
Regardless, since I am inserting a row, the method is being called on all my rows, including the one I want to change. I checked that it is returning the UITableViewCellEditingStyleDelete
. Even though it returns the correct value, though, it still shows the plus icon instead of the minus icon.
Calling [tableview reloaddata]
does not work.
There is an editingStyle
property on the UITableViewCell
, which seems like it would solve my problems, but it is read only.
It is as if once the tableView:editingStyleForRowAtIndexPath:
method has set the editingStyle
, this can never be changed. Why, then, would this method be continuously called when rows are scrolled into view?
How can I change the editing control of a UITableViewCell?
You'll notice that in Apple's Contacts application, there is the same exact behavior, except that it is transitioning from UITableViewCellEditingStyleNone
instead of UITableViewCellEditingStyleInsert
. This can be seen by editing a contact, and then typing a number in the last phone field (i.e. adding a new phone number): the current row gets a minus button, and a new row is added beneath it.