views:

20

answers:

2

I have a UITableViewController subclass. I set self.editing = YES at the end of the viewDidLoad method, but when the table is displayed the little red 'delete' icon does not appear next to each row.

Then, I added an edit button to the navigation item:

self.navigationItem.rightBarButtonItem = self.editButtonItem;

When I launch the application now, it starts in edit mode (I can tell because the edit button says 'done') but, again, the delete icons don't appear. Then if I toggle it with the edit button twice (once to turn it off, then once to turn it on), the red delete icons appear.

So, my question is: why aren't the table cells displaying correctly when first displayed? I've tried moving the self.editing = YES line to other places in the code, like in the init function or the viewWillAppear function, but no dice. It seems like this is a result of funny ordering somewhere (e.g. table cells initialized before editing is set, or something), but I can't figure it out; running the debugger shows that the viewDidLoad call happens before cellForRowAtIndexPath, as one would expect.

Other notes:

  • Yes, I am having editingStyleForRowAtIndexPath return UITableViewCellEditingStyleDelete. But from debugging I've verified that that function is not even called after the first load. (It gets called after I toggle editing mode twice.)
A: 

Try using the

- (void)setEditing:(BOOL)editing animated:(BOOL)animate

method in UITableView

willcodejavaforfood
switching to the setEditing:animated message had no effect, but it was an interesting suggestion (makes sense that the edit button would call that message, and that this message *could* do stuff in addition to setEditing:(BOOL)editing).
unsorted
A: 

d'oh, adding it in viewDidAppear (or, better: viewWillAppear) did the trick. Thanks @lukya and @willcodejavaforfood for suggestions.

I feel silly. I swear I thought I'd checked that.

Moral of the story: setting the editing property too early makes page elements not display in editing mode. (Doesn't that seem like a bug?)

unsorted