Re: Starting editing a Row as soon as it is Added.
Hamish Allan <[email protected]>
| Newsgroups | gmane.comp.macosx.devel |
|---|---|
| Message-ID | <[email protected]> |
Please excuse the brevity -- sent from my phone On 19 Oct 2009, at 06:53, Joshua Garnham <joshua.garnham-/[email protected]> wrote: > Ah, I see. Thanks for the help Hamish. > So do i need to use the NSTableView's selectedRow method? Are you asking, or are you saying you tried this and it didn't work? H > Like … > NSWindow *w = [outlineView window]; > BOOL editingEnded = [w makeFirstResponder:w]; > if (!editingEnded) { > return; > } > > NSObject *p = [treeController newObject]; > [treeController addObject:p]; > > // Find the row of the new object > int row = [outlineView selectedRow]; > > // Start editing in the second column > [outlineView editColumn:1 > row:row > withEvent:nil > select:YES]; > > Josh > > From: Hamish Allan <[email protected]> > To: Joshua Garnham <joshua.garnham-/[email protected]> > Cc: "[email protected]" <[email protected]> > Sent: Monday, 19 October, 2009 0:16:40 > Subject: Re: Starting editing a Row as soon as it is Added. > > > > Please excuse the brevity -- sent from my phone > > On 18 Oct 2009, at 18:00, Joshua Garnham > <joshua.garnham-/[email protected]> wrote: > > > The way I got this code was by reading Aaron Hillegass' Cocoa > Programming for Mac OS X and there was a specific section explaining > how to Start editing a Row as soon as it is added and I've tried to > adapt that code because he had an array controller and I have a > tree controller he called arrangedObjects then compared the object p > to the ones in that array but calling arrangedObject on a tree > controller does not return an array. > > I think what Christiaan is driving at is that you need to consider > *why* it does not return an array, rather than just trying to > substitute some other method because that *does* return an array. > > The relationship between model and view is more complex for a tree / > outline view than an array / table view, not least because branches > can be expanded and collapsed. > > Luckily most of it is taken care of for you because you can > determine which item is selected. You just need to know which row > that item is at. NSOutlineView derives from NSTableView, so it has a > method for this. > > H > > > So I am not sure what I need to change/ What I've got wrong . > > > > Josh. > > > > > > ________________________________ > > From: Christiaan Hofman <[email protected]> > > To: Joshua Garnham <joshua.garnham-/[email protected]> > > Sent: Sunday, 18 October, 2009 17:22:32 > > Subject: Re: Starting editing a Row as soon as it is Added. > > > > Why don't you read the docs? It's all in there. And the answer is > no. > > > > Christiaan > > > > > > On Oct 18, 2009, at 16:16, Joshua Garnham wrote: > > > > Ok, So do I need to retrieve all the objects in the Outline View > to put in the NSArray? > >> And what is the Object p then if it's not an element in the array? > >> > >> > >> Josh. > >> > >> > > ________________________________ > > From: Christiaan Hofman <[email protected]> > >> To: Joshua Garnham <joshua.garnham-/[email protected]> > >> Cc: [email protected] > >> Sent: Sunday, 18 October, 2009 14:51:40 > >> Subject: Re: Starting editing a Row as soon as it is Added. > >> > >> > >> > >> On Oct 18, 2009, at 14:20, Joshua Garnham wrote: > >> > >> Oh, I see. > >>> So from your reply I tried this: > >>> > >>> > >>> NSObject *p = [treeController newObject]; > >>> [treeController addObject:p]; > >>> > >>> // Find the row of the new object > >>> NSArray *a = [treeController selectedNodes]; > >>> int row = [a indexOfObjectIdenticalTo:p]; > >>> > >>> // Start editing in the first column > >>> [outlineView editColumn:0 > >>> > >>> row:row > >>> withEvent:nil > >>> select:YES]; > >>> > >>> However this still does not work, it just adds an object but > does not begin editing it. > >>> > >>> Josh > >>> > >> > >> > >> > >> And what makes you think that the index of the object in the > selected nodes has anything to do with the row index in the > outlineview? Moreover, why do you even think that the object p is an > element of the array a > >> (hint: it's not). > >> > >> > >> Christiaan > >> > >> > >> > > ________________________________ > > From: Christiaan Hofman <[email protected]> > >>> To: Joshua Garnham <joshua.garnham-/[email protected]> > >>> Cc: [email protected] > >>> Sent: Sunday, 18 October, 2009 10:44:02 > >>> Subject: Re: Starting editing a Row as soon as it is Added. > >>> > >>> > >>> 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 > >>> > >>> > >>> > >>> > >> > >> > >> > > > > Send instant messages to your online friends http://uk.messenger.yahoo.com > > _______________________________________________ > > MacOSX-dev mailing list > > [email protected] > > http://www.omnigroup.com/mailman/listinfo/macosx-dev >