NSOutlineView reloadItem: has no effect

后端 未结 4 1092
孤独总比滥情好
孤独总比滥情好 2020-12-29 07:30

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

4条回答
  •  旧巷少年郎
    2020-12-29 08:06

    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)
    

提交回复
热议问题