• 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: get the selection in an NSOutlineView
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: get the selection in an NSOutlineView


  • Subject: Re: get the selection in an NSOutlineView
  • From: Graham Cox <email@hidden>
  • Date: Wed, 9 Jun 2010 14:40:21 +1000

On 09/06/2010, at 2:29 PM, Rua Haszard Morris wrote:

> I have an NSOutlineView which has a single column, and 2 levels of tree - each item in the list can have child items but those subitems don't have children.
>
> How can I determine the selected items?


-selectedRowIndexes


>
> NSTableView -selectedRow returns row indices that change dependent on whether parent items are expanded, so that won't do.
> I could attempt to keep track of the selection via delegate method outlineView:shouldSelectItem: but this seems a bad idea.
>
> Am I missing something? Surely it is possible to ask an NSOutlineView which items are selected?


Yes, as above. But bear in mind that the row index has a dynamic relationship with the indexes of items in your data model, because the user can expand and collapse items at will. At the time you call -selectedRowIndexes, you should then extract the items corresponding to those indexes from your data model (e.g. using [NSArray objectsAtIndexes:]) before the user has a chance to change the arrangement.

It's also usual to track the selection as it changes in the delegate using the -outlineViewSelectionDidChange: method. You can also get the item associated with a row using [NSOutlineView itemForRow:]

--Graham


_______________________________________________

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: get the selection in an NSOutlineView
      • From: Jens Alfke <email@hidden>
References: 
 >get the selection in an NSOutlineView (From: Rua Haszard Morris <email@hidden>)

  • Prev by Date: get the selection in an NSOutlineView
  • Next by Date: Invalid exception being thrown: CIUnsharpMask is not kvc for the key inputIntensity - except that it is
  • Previous by thread: get the selection in an NSOutlineView
  • Next by thread: Re: get the selection in an NSOutlineView
  • Index(es):
    • Date
    • Thread