Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Tylox

macrumors newbie
Original poster
Feb 21, 2008
10
0
San Jose, CA
Howdy,

I am currently working my way through the Hillegass book and just finished the second challenge to Chapter 6, sorting a NSTableView without using Bindings or the NSController class.

After spending approximately 2 evenings digging through the class reference documents at Apple, I narrowed down my search to one of three documents for the code I needed to implement:

NSSortDescriptor

Creating and Using Sort Descriptors

NSTableDataSource Protocol Reference

This is where I got stuck. I understood that I somehow needed to implement sortDescriptors; however, since the class documentation only tends to list the method and a brief summary of what it does, I did not grasp how to connect sortDescriptors to my TableView.

After getting frustrated with the Apple documentation, I started googling around for similar example code. I originally avoided this approach as I didn't want to accidently come across the answer. I wanted to figure out the logic behind the code I needed to insert...

I found out the answer was, quite simply, to drop the following method in the myDocument class:

Code:
- (void)tableView:(NSTableView *)aTableView sortDescriptorsDidChange:(NSArray *)oldDescriptors

Now of course, as I am now writing this the day after the exersize, I realized WHY this works...delegates! (I should have realized this right away with the "...DidChange" syntax, but I'm still pretty new to this).

My question is...I feel if the Apple documentation contained more details in their descriptions or links example code showing how to implement said code, I would have solved this puzzle much earlier. Is this mainly because I am still new to Cocoa programming, while an advanced programmer would instantly see that method and know exactly how to implement it? If not, what are some suggestions for further resources to learn this information?

Thanks for your help!
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.