Problem Background:
I have a NSOutlineView with every tableColumn binded programmatically to the NSTreeController's arrangedObjects so there is no need to bind selectionIndexPaths. The source of NSTreeController's arrangedObjects is a mutableArray. I'm adding all nodes to the NSTreeController dynamically by performing - (void)insertObject:(id)object atArrangedObjectIndexPath:(NSIndexPath *)indexPath;
on main thread. I have overridden NSOutlineView's mouseDown event in the way like:
- (void)mouseDown:(NSEvent *)event { /*...myMethods...*/ [super mouseDown:event]; }
The Problem:
When the nodes are being added very fast and I perform the mouseDown event on the outlineView, then very often the next situation takes place:
the thread that adds nodes to TreeController interrupts the sequence (I guess) called by mouseDown event so insertObject: atArrangedObjectIndexPath:
is called before then setSelectionIndexPaths:
. That's why the new selection in outlineView disappears and treeController still has the old version of selectedIndexPaths.
I've tried one partial solution: blocked my insertObject:
method (with @synthesized(outlineView)
) so that it couldn't change the entire of outlineView, but it often rises in thread conflict and app freezes.
Are there any ideas how to solve the problem with disappearing selections?