Re: NSOutlineView - Automatically select newly added item - Help needed
Re: NSOutlineView - Automatically select newly added item - Help needed
- Subject: Re: NSOutlineView - Automatically select newly added item - Help needed
- From: Corbin Dunn <email@hidden>
- Date: Tue, 06 Oct 2009 07:28:48 -0700
Mario,
On Oct 5, 2009, at 4:44 PM, Mario Kušnjer wrote:
> Hello to the list !
>
> Request for help regarding a little problem.
> So I have this piece of code:
>
> - (IBAction)addNewItem:(id)sender
> {
> if ([lsOutlineView selectedRow] < 0)
> {
> [sourceListLevelZero addObject:[Parent new]];
> [lsOutlineView reloadItem:nil reloadChildren:YES];
> [lsOutlineView expandItem:nil expandChildren:YES];
> [lsOutlineView selectRowIndexes:[NSIndexSet indexSetWithIndex:[lsOutlineView rowForItem:[Parent new]]] byExtendingSelection:NO];
> }
> ...
> }
In addition to what others said, your main misunderstanding is two things:
1. The outlineview identifies unique objects by the pointer address, not "isEqual". Thus this line creates a new "Parent" object:
> [sourceListLevelZero addObject:[Parent new]];
and this line creates a new (different) Parent object:
> [lsOutlineView rowForItem:[Parent new]]]
2. I highly recommend reading up on memory management in Cocoa (unless you are creating a GC application). The [Parent new] lines are leaking memory. new is a shortcut for 'alloc/init' and returns a retained object.
corbin_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden