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
Apple seems to have "fixed" it.
WWDC 2016, presentation 203 "What's New in Cocoa" at 30:35 in the video:
"NSOutlineView
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.
reloadItem:
works only on macOS 10.12.
From release notes: https://developer.apple.com/library/content/releasenotes/AppKit/RN-AppKit/
NSOutlineView will now reload the cell views associated with ‘item’ when [outlineView reloadItem:] is called. The method simply calls [outlineView reloadDataForRowIndexes:columnIndexes:] passing the particular row that is to be reloaded, and all the columns. For compatibility, this will only work for applications that link against the 10.12 SDK.
So, if you want to reload row on earlier systems, you should use -reloadDataForRowIndexes:columnIndexes:
.
Something like that:
let index = outlineView.row(forItem: obj)
let rowIndex = IndexSet(integer: index)
let cols = IndexSet(0 ... outlineView.numberOfColumns)
outlineView.reloadData(forRowIndexes: rowIndex, columnIndexes: cols)
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