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 (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to