Sort in second challenge


#1

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

for

but it doesn’t work too…

ps : sorry for my poor english :blush:


#2

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];
}

#3

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 :
viewtopic.php?f=14&t=1279

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


#4

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: pretty-function.org]


#5

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