How to force NSOutlineView to call outlineView:numberOfChildrenOfItem

81 Views Asked by At

After my method finishes, NSOutlineView calls outlineview:child:ofIndex: for reasons that are not clear to me.

It does not call outlineview:numberOfChildrenOfItem first.

Since I deleted an item from my data in the method, I get an error in outlineview:child:ofIndex: when the index exceeds the number of remaining children.

Any work-around would be an acceptable answer.

1

There are 1 best solutions below

1
Willeke On

The outline view doesn't know when the data changes so you must keep the data and the outline view in sync. One way of doing this is inserting, moving and removing rows with:

func insertItems(at indexes: IndexSet, inParent parent: Any?, withAnimation animationOptions: NSTableView.AnimationOptions = [])
func moveItem(at fromIndex: Int, inParent oldParent: Any?, to toIndex: Int, inParent newParent: Any?)
func removeItems(at indexes: IndexSet, inParent parent: Any?, withAnimation animationOptions: NSTableView.AnimationOptions = [])

Another way is reloading:

func reloadData()
func reloadItem(_ item: Any?)
func reloadItem(_ item: Any?, reloadChildren: Bool)