I have a subclass of NSTreeController where I've added a method for adding an object at a particular index path based on the current selection in an outline view. It's worked fine for almost a decade on every version of MacOS inbetween then and now. However a new client who just started using the app found a bug that I cannot for the life of me reproduce. She is using MacOS 11.4 and on a 2020 iMac i7. I'm on 11.5.2 and cannot get the same result with the exact same dataset.
When the user clicks the "Add Group" button in the window the IBAction below runs. It should...
- Create a new object
- Insert the new object directly below the current selection or at the top if nothing is selected
- Select the new row and enter editing mode
The client is experiencing an error where the action doesn't insert anything but just selects the expected tree item and enters editing. I've posted a video she took for reference at (sorry the forum doesn't allow me to link or upload)
https://youtu.be/pV9-PjUsQrE
-(IBAction)addGroup:(id)sender
{
NSIndexPath *theIndexPath = [self selectionIndexPath];
id theObject = [[self objectClass] new];
[theObject setMyType:@"group"];
NSTreeNode *theTreeNode = [NSTreeNode treeNodeWithRepresentedObject:theObject];
if (!theIndexPath) // nothing is selected - maybe the array is empty
{
theIndexPath = [NSIndexPath indexPathWithIndex:0];
}
else
{
theIndexPath = [NSIndexPath indexPathWithIndex:[theIndexPath indexAtPosition:0]+1];
}
[self insertObject:theTreeNode atArrangedObjectIndexPath:theIndexPath];
[[self myOutlineView] editColumn:0 row:[[self myOutlineView] selectedRow] withEvent:nil select:YES];
}
It seems like insertObject: atArrangedObjectIndexPath: is failing. The odd thing is you can see that she was able to insert several items successfully prior to this error occurring. Further, the tree objects are in a MySQL database and I can connect to using the same app version she is using and I have no issues. Why would this be happening?