Challenge 2 all code


So, that was fun. It took a while for me to get Challenge 2, but when I did I wanted to redo it without using the sort criteria embedded in the .xib file. So, into the documentation (“Sorting Table View Rows”, if you don’t want to hunt around with different searches). Found some likely looking code. Implanted it into tableView:sortDescriptorsDidChange: and changed it around to match the rest of my code. That didn’t work worth sour apple cores. OK, engage logic, it must need to know all this stuff earlier than when that gets triggered. What’s earlier than init? Nothing! Implanted it there. That worked almost exactly not at all as much as the previous attempt. OK, says me to myself, re-engage logic. Hey logic, thanks a bunch for that red herring. Clearly the program doesn’t know about things in the .xib until after it loads the .xib/nib, and there just happens to be a method in the template called windowControllerDidLoadNib:. What say we try putting it there? Logic hangs its head in shame and does not respond, but I try that anyway. Voila, it works! All the setup in code:

[code]- (void)windowControllerDidLoadNib:(NSWindowController *)aController
[super windowControllerDidLoadNib:aController];
// Add any code here that needs to be executed once the windowController has loaded the document’s window.
NSTableColumn *tableColumn = [tableView tableColumnWithIdentifier:@“personName”];
NSSortDescriptor *sortDescriptor = [NSSortDescriptor sortDescriptorWithKey:@"personName"
[tableColumn setSortDescriptorPrototype:sortDescriptor];

tableColumn = [tableView tableColumnWithIdentifier:@"expectedRaise"];
sortDescriptor = [NSSortDescriptor sortDescriptorWithKey:@"expectedRaise"
[tableColumn setSortDescriptorPrototype:sortDescriptor];

It seems to pass all testing. However, logic (still pouting like an angst-ridden tweener who is not allowed to go see the premiere of the latest Twilight movie) wants to know if that is the proper way of doing this? It seems reasonable, I came to the conclusion of putting it all in windowControllerDidLoadNib: because I figured if that information is otherwise imbedded in the .xib, then the program becomes aware of it when it loads the .xib/nib, so a reasonable place to put equivalent (I hope) code would be right after the .xib/nib loads.

It really ends up being not much code for the number of brain cells that had to line up and rub together to generate enough electricity to fire a neuron or two (I know, I hate to fire a good neuron, but the job market is tough out there).