Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Sorting dilemna

Sorting dilemna
Thread Tools
Professional Poster
Join Date: Sep 2000
Location: San Francisco
Status: Offline
Reply With Quote
Apr 7, 2002, 11:39 AM
 
I have an NSTableView that displays a list of records from an NSMutableDictionary which is a dictionary of custom objects called Reference. Each Reference contains several attributes including an NSString called referenceYear. I would like to display the NSTableView records in descending order with respect to the referenceYear. My problem is that I have some actions that are triggered by a double click on a record in the NSTableView and use the rowCount to then access the appropriate entry in the NSMutableDictionary. If I sort the display of records, how do I then map the double-click to the appropriate record?

My only thought is that this is going to require sorting the dictionary using a custom sort algorithm that uses the referenceYear to order the NSMutableDictionary prior to everything. I don't really care about the order of the dictionary, so this should be okay. Are there any other solutions that anyone can think of? I imagine that displaying records in an NSTableView and then mapping rowClicked to the appropriate dictionary object is a common problem.

kman
     
Professional Poster
Join Date: Dec 2000
Location: Chicago, Illinois
Status: Offline
Reply With Quote
Apr 7, 2002, 01:48 PM
 
Keep all your data in the NSMutableDictionary, but then also create an NSMutableArray from that . Then you can use NSArrays sortBySelector method as needed. At least that's what I do.

HTH,
F-bacher
     
kman42  (op)
Professional Poster
Join Date: Sep 2000
Location: San Francisco
Status: Offline
Reply With Quote
Apr 7, 2002, 02:20 PM
 
Hey. That rocks! I've been finding that the hardest part about learning Cocoa programming is learning all of the foundation kit/appkit classes and the methods they already contain. I really wish there was a reference book detailing everything with sample code. I find searching the cocoa help files to be frustrating. Call me old-fashioned, but I'd much rather just flip through a book to find what I need. On the positive side, most of the methods in one class have analogues in other classes.

Anyway, thanks.

kman

[ 04-07-2002: Message edited by: kman42 ][/LIST]
[ 04-07-2002: Message edited by: kman42 ]
     
kman42  (op)
Professional Poster
Join Date: Sep 2000
Location: San Francisco
Status: Offline
Reply With Quote
Apr 7, 2002, 03:10 PM
 
One last question. Is there an easy way to reverse the sorted array? I've thought of just reversing the NSOrderedAscending and NSOrderedDescending, but that seems like it would make the code hard to read.

thanks,
kman
     
Grizzled Veteran
Join Date: Feb 2001
Location: Germany
Status: Offline
Reply With Quote
Apr 7, 2002, 04:31 PM
 
Originally posted by kman42:
<STRONG>One last question. Is there an easy way to reverse the sorted array? I've thought of just reversing the NSOrderedAscending and NSOrderedDescending, but that seems like it would make the code hard to read.

thanks,
kman</STRONG>
just an idea, haven't tried this out, but what about [[yourArray reverseObjectEnumerator] allObjects] ?
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 11:13 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2