Sort in second challenge


hy, i have a problem : sort doesn’t work on the second challenge

i used datasource method, but it doesn’t do anything :

-(void)tableView:(NSTableView *)tableView sortDescriptorsDidChange:(NSArray *)oldDescriptors{ NSArray *newDescriptors = [tableView sortDescriptors]; [employees sortUsingDescriptors:newDescriptors]; [tableView reloadData]; }

but adding, editing and deleting employees from tableview work

one warning appears : local declaration of 'tableView hides instance variable, so i changed


but it doesn’t work too…

ps : sorry for my poor english :blush:


Have you checked to see if the tableView:sortDescriptorsDidChange: method is being called at all?

- (void)tableView:(NSTableView *)tableView sortDescriptorsDidChange:(NSArray *)oldDescriptors
    NSLog (@"%s: %@", __PRETTY_FUNCTION__, tableView);

    NSArray *newDescriptors = [tableView sortDescriptors];
    NSLog (@"%s: Before: %@", __PRETTY_FUNCTION__, employees);
    [employees sortUsingDescriptors:newDescriptors];
    NSLog (@"%s: After: %@", __PRETTY_FUNCTION__, employees);

    [tableView reloadData];


i’ve copy your code, this method isn’t called

i don’t understand, i’ve linked my tableview with datasource, and those methods :

-(int)numberOfRowsInTableView:(NSTableView *)aTableView
-(id)tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row
-(void)tableView:(NSTableView *)aTableView setObjectValue:(id)object forTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row

are working

clicking on tableview header just color the column in blue

EDIT : i’vs just saw i’m at the wrong topic… i have trouble with second challenge of chapter 8

I have this exactly same problem :

but i use a recent version of xcode, and arc for memory management


Then check to see, in IB, if the Sort Key and Selector attributes are set for table columns.

[Accelerate your learning and become a competent programmer:]


It works, thank you! i thought it wasn’t necessary when we don’t use arrayController :blush: