• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NSOutlineView - Automatically select newly added item - Help needed
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

  • Follow-Ups:
    • Re: NSOutlineView - Automatically select newly added item - Help needed
      • From: Mario Kušnjer <email@hidden>
    • Re: NSOutlineView - Automatically select newly added item - Help needed
      • From: Mario Kušnjer <email@hidden>
References: 
 >NSOutlineView - Automatically select newly added item - Help needed (From: Mario Kušnjer <email@hidden>)

  • Prev by Date: Re: self release
  • Next by Date: Re: self release
  • Previous by thread: Re: NSOutlineView - Automatically select newly added item - Help needed
  • Next by thread: Re: NSOutlineView - Automatically select newly added item - Help needed
  • Index(es):
    • Date
    • Thread