 |
 |
Sorting dilemna
|
 |
|
 |
|
Professional Poster
Join Date: Sep 2000
Location: San Francisco
Status:
Offline
|
|
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
|
|
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
|
|
|
| |
|
|
|
 |
|
 |
|
Professional Poster
Join Date: Sep 2000
Location: San Francisco
Status:
Offline
|
|
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 ]
|
|
|
| |
|
|
|
 |
|
 |
|
Professional Poster
Join Date: Sep 2000
Location: San Francisco
Status:
Offline
|
|
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
|
|
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] ?
|
|
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
Forum Rules
|
 |
 |
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
 |
 |
 |
 |
|
 |