Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSOutlineView reloadItem: has no effect

I'm trying to release some strain on a view-based NSOutlineView for which I changed a single item property and which I initially reloaded just fine using [myOutlineView reloadData].

I tried [myOutlineView reloadItem: myOutlineViewItem] but it never calls - (NSView *)outlineView:(NSOutlineView *)ov viewForTableColumn:(NSTableColumn *)tableColumn item:(id)item and consequently the data is not updated.

-(void)reloadOutlineViewObject
{
    //[myOutlineView reloadData];   //Reload data just fines but is ressource-hungry
    NSLog(@"%d",[myOutlineView rowForItem:myOutlineViewItem]; //Making sure my object is an item of the outlineView, which it is !
    [myOutlineView reloadItem:myOutlineViewItem];   
}

Am I missing something here ?

UPDATE

As pointed out in the comments, my outlineView is view-based.

UPDATE 2

Trying out some stuffs made me realized that the object I am reloading is a second-level object (cf object tree) and calling reloadItem:firstLevelObject reloadChildren:YES does work.

Would it be possible that we can only call reloadItem: on first-level object ? That would be highly inefficient in my case (I only have one two level item and plenty of second level) !

nil ->firstLevelA ->secondLevel1
                  ->secondLevel2
    ->firstLevelB ->secondLevel3
                  ->secondLevel4

Gonna try to subclass NSOutlineView and rewrite reloadItem: in the mean time.

UPDATE 3

I took a look at NSOutlineView in Cocotron to get start and felt that the code I needed to write to overwrite reloadItem would be quiet heavy. Anyone to confirm ?

like image 246
Bertrand Caron Avatar asked Nov 13 '13 19:11

Bertrand Caron


3 Answers

I encountered this same problem with a view-based outline view, where calling -reloadItem: seems to just not do anything. This definitely seems like a big bug, though the documentation doesn't explicitly say that reloadItem will reacquire the views for that row.

My workaround was to call NSTableView's -reloadDataForRowIndexes:columnIndexes: instead, which seems to work as expected, triggering a call to the -outlineView:viewForTableColumn:item: delegate method for just that item. You can get the row that needs to be reloaded by calling -rowForItem: and passing in the item you want to reload.

like image 170
Brian Webster Avatar answered Nov 08 '22 23:11

Brian Webster


This really isn't a bug - it was something I had explicitly designed. My thought was that reloadItem (etc) should just reload the outline view item properties, not the table cell at that item, since it doesn't carry enough specific information on what to reload (such as what specific cell you might want reloaded). I had intended for people to use reloadDataForRowIndexes:columnIndexes: to reload a particular view based tableview cell; we usually don't provide cover methods when the base class can easily do the same thing with just a few lines of code.

However, having said that, I know multiple people have gotten confused about this, and most people expect it to reload the cell too.

Please log a bug requesting Apple to change this.

thanks, -corbin

like image 11
corbin dunn Avatar answered Nov 09 '22 00:11

corbin dunn


Apple seems to have "fixed" it.

WWDC 2016, presentation 203 "What's New in Cocoa" at 30:35 in the video:

"NSOutlineView

  • Reloads cell views associated with the 'item' when reloadItem() is called"
like image 4
thetrutz Avatar answered Nov 09 '22 00:11

thetrutz