Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSArrayController : removeAllObjects does not refresh TableView

In my application I add objects directly to an ArrayController. When I want to clean all items I do:

[[downloadItemsController content] removeAllObjects];

This command however does not refresh the TableView the arraycontroller is bound to. If I remove all items and add another new items I only see that item. That is fine but if I don't add anything I still have all my items in the table.

If I do

[downloadItemsController prepareContent];

all old items are removed from the tableview but than I will get an new and empty item I can edit. I don't want that and because one of my columns has a checkboxcell I always get an row with a checkbox.

I just need an empty table with no items after I remove all existing items.

like image 255
TalkingCode Avatar asked Aug 02 '10 20:08

TalkingCode


2 Answers

To quickly remove all the objects from an NSArrayController object:

NSRange range = NSMakeRange(0, [[anArrayController arrangedObjects] count]);
[anArrayController removeObjectsAtArrangedObjectIndexes:[NSIndexSet indexSetWithIndexesInRange:range]];

The bindings should update automatically. See original SO answer.

like image 164
bdunagan Avatar answered Sep 28 '22 01:09

bdunagan


This is because you're modifying the controller's content "behind its back." Try using the array controller's -removeObjects: method.

like image 29
Joshua Nozzi Avatar answered Sep 28 '22 02:09

Joshua Nozzi