Search code examples
macoscocoanstableviewappkitnsoutlineview

How can I force a view-based NSOutlineView to reload the views for an item?


I have a datasource/view-based NSOutlineView, which has the ability to change the type of data represented in a row, even though the actual item object reference stays the same. When this mutation occurs, one of the columns needs to load a different NSTableCellView. I've tried doing the following after the mutation:

[outlineView reloadItem:updatedItem reloadChildren:YES];

When that gets called, the following NSOutlineViewDataSource methods get called:

-outlineView:isItemExpandable:
-outlineView:child:ofItem:

But this method never gets called:

-outlineView:viewForTableColumn:item:

How can I force the NSTableView to actually reload the views for a specific item?


Solution

  • you need to use

    - (void)reloadDataForRowIndexes:(NSIndexSet * nonnull)rowIndexes columnIndexes:(NSIndexSet * nonnull)columnIndexes
    

    to ensure that your viewForTableColumn delegate method is called.