Re: Starting editing a Row as soon as it is Added.
Christiaan Hofman <[email protected]>
| Newsgroups | gmane.comp.macosx.devel |
|---|---|
| Message-ID | <[email protected]> |
On Oct 18, 2009, at 10:41, Joshua Garnham wrote: > I have an NSOutlineView and what I want to happen is that when a row > is > added I want the row that has been added to Start Editing immediately > like when you double click on a row. > > I've tried this: > > NSObject *p = [treeController newObject]; > [treeController addObject:p]; > > NSManagedObjectContext *moc = [self managedObjectContext]; > NSEntityDescription *entityDescription = [NSEntityDescription > entityForName:@"projects" inManagedObjectContext:moc]; > NSFetchRequest *request = [[[NSFetchRequest alloc] init] autorelease]; > [request setEntity:entityDescription]; > > NSError *error = nil; > NSArray *a = [moc executeFetchRequest:request error:&error]; > > // Find the row of the new object > int row = [a indexOfObjectIdenticalTo:p]; > > // Start editing in the second column > [outlineView editColumn:1 > row:row > withEvent:nil > select:YES]; > > However, it seems that just edits any row in my Outline View. > What have I done wrong?? > > Josh I'm not surprised this won't work, I'm much more surprised you actually expect it to work. Why do you think that the index of an object in an arbitrary fetch result is in any way related to the row for that object in your outlineView? So you just need to figure out the row from inspection of the real display model, i.e. ask the treeController and/or the outlineView. You definitely want the treeController to select inserted objects, so you can just get the selected node afterwards. And you can get its row from the outlineView. Christiaan