Reputation: 6337
It would seem like there should be an API on UITableViewDelegate (or maybe even UITableViewDataSource) to let the delegate know when a UITableView changes editing state. But I can't find anything like that.
I suppose I could use KVO to detect it, but I don't want to unless I have to.
Am I missing something? Or is there really no API for this?
Upvotes: 0
Views: 604
Reputation: 4267
From what I can understand from this page, the delegate method tableView:canEditRowAtIndexPath:
is also called when the edit button is tapped.. Which means that you don't have to subclass the tableview. I haven't tried this myself, but I'm pretty sure this will do the trick. See the link for more details.
Update:
It is a bit messy to do it like this, as the method is called once for every cell. The correct way would be to use the method Daniel Thorpe mentions in his answer (setEditing:animated:
). But I would just override the method in the UITableViewController
being used (unless you have a subclass that you are working with).
By the way, here is another thread about the exact same thing here on SO: link.
Upvotes: 1
Reputation: 3931
Well, UIViewController defines - (void)setEditing:(BOOL)editing animated:(BOOL)animated which you can override in your subclass. Always call the superclass implementation, but that gives you an opportunity to modify the table (such as inserting/removing rows) when transitioning between states.
Upvotes: 1