I have a Outlineview using a NSTreeController, for the most part everything is functioning as I would like except when a new item is added, I would like the item automatically selected for editing. In the past when using a NSTableview I would determine the row the item is located and used the function
- (void)editColumn:(NSInteger)columnIndex row:(NSInteger)rowIndex withEvent:(NSEvent *)theEvent select:(BOOL)flag
However, since NSOutlineView uses NSindexPath, I’m struggling with how to accomplish this, so is there a function available to pass a NSIndexpath as opposed to a row to achieve the same result. Or should I have a different approach for NSOutlineView.
Turns out my problem was related to the addChild method, the documentation for addChild indicates the following;
Special Considerations
Beginning with OS X v10.4 the result of this method is deferred until the next iteration of the runloop so that the error presentation mechanism can provide feedback as a sheet.
So, I added the following, with the corresponding selector
[self performSelector:@selector(editNewSector:) withObject:nil afterDelay:0];
Everything seems to be working now,my code is below
- (IBAction)addChildSector:(id)sender
{
[[self myTreeController] addChild:sender];
[self performSelector:@selector(editNewSector:) withObject:nil afterDelay:0];
}
- (IBAction)editNewSector:(id)sender
{
NSTreeNode *nodeSector = [[self myOutlineView]
itemAtRow:[[self myOutlineView] selectedRow]];
NSInteger row = [[self myOutlineView] rowForItem:nodeSector];
[[self myOutlineView] editColumn:0 row:row withEvent:nil select:YES];
}