• 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: Sorting in an NSTableView
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Sorting in an NSTableView


  • Subject: Re: Sorting in an NSTableView
  • From: Julian Barkway <email@hidden>
  • Date: Fri, 3 May 2002 18:41:01 +0200

On Friday, May 3, 2002, at 05:16 pm, Andrew Baldwin wrote:

I need to sort in an NSTableView, what is the best way to do this without sorting the original source of the data? Should I create an NSArray of strings/numbers which can be displayed in the table and which have an instance variable referring back to the original datasource or is there a better/"more cocoa" way to do this?

(I need to access the original datasource if the user clicks on an item in the NSTableView)

Thanks in advance,
Andrew
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.


It sounds like you are making a false assumption about the relationship between your datasource and the displayed data. Even if you sort the datasource array, presuming you do a reloadData in the interim, the index returned by your table view's 'selectedRow' method will always directly relate to your datasource, such that you can use a construct like this to access your array:

myObject = [aSortedArray objectAtIndex: [aTableView selectedRow]];

If, in spite of this, you still need to sort a separate array, the best approach is to use a dictionary as your underlying data structure, use allKeys (?) to create an array of sort keys and access that as above to get a key into your dictionary.

Julian.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

References: 
 >Sorting in an NSTableView (From: Andrew Baldwin <email@hidden>)

  • Prev by Date: Re: CallBack method design
  • Next by Date: Returns from a sheet
  • Previous by thread: Sorting in an NSTableView
  • Next by thread: Seeing/Viewing/browsing a stacktrace
  • Index(es):
    • Date
    • Thread