NSTableView batch update issue

I create a simple list, there are two kind of item: conversation and message, if click a conversation, it will expand it's messages. So there will be some insert and remove updates. I calculate the difference results and perform the batch update.

displayItems = newDisplayItems

tableView.beginUpdates()

tableView.removeRows(at: IndexSet(removeIndex), withAnimation: [.effectFade, .slideUp])
tableView.insertRows(at: IndexSet(insertIndex), withAnimation: [.effectFade, .slideDown])

tableView.endUpdates()

In most cases, the animation looks fine, but when the mock data is large (> 1000?) and called scrollRowToVisible to scroll to the last row in viewDidAppear, then click some conversations above, the UI broken.

Is there something wrong? Would appreciate help from someone experienced with NSTableView.

Example code

You might need a NSOutlineView instead since you're displaying hierarchical data.

For more information about using NSOutlineView in your app, see Navigating Hierarchical Data Using Outline and Split Views

My example is hierarchical data, but it is not the key point. I can create another example with flat data.

The key point is when NSTableView has a lots of rows, scrollRowToVisible from top to bottom. Insert some rows with different height, it UI broken.

I guess NSTableView jump from top to bottom, it doesn't calculate a full height.

NSTableView batch update issue
 
 
Q