Challenge 2: tableView:sortDescriptorsDidChange: not called


#1

Hello,

I’ve done Challenge 2, and everything is working fine (i.e. numberOfRowsInTableView:, tableView:objectValueForTableColumn:row: and – tableView:setObjectValue:forTableColumn:row: are getting called). Except for the sorting part.

I tried to implement sorting by providing an implementation for tableView:sortDescriptorsDidChange:, as explained in the “For the More Curious” section, but apparently this method is never getting called in my application (verified by putting a breakpoint in it). How is this possible? What am I doing wrong?

By the way: The challenge made us implement the RaiseMan application without using bindings, which rely on KVC. But the search mechanism that employs tableView:sortDescriptorsDidChange: also relies on KVC (though not on bindings). The documentation says this method was added with 10.3. Did bindings exist before 10.3? Did bindings already exist in OpenStep? How was sorting NSTableViews accomplished before 10.3 / in OpenStep?

Regards,
tajmahal


#2

I am having the exact same problem! Here’s my code:

RMDocuments.m

- (void)tableView:(NSTableView *)aTableView sortDescriptorsDidChange:(NSArray *)oldDescriptors { NSLog(@"sorting method called"); NSArray *newDescriptors = [aTableView sortDescriptors]; [employees sortUsingDescriptors:newDescriptors]; [tableView reloadData]; }

When it is run I do not get any sorting response by clicking on the column header (and also no NSLog output i.e. the method is not called)

I tried implemented sorting using the method described in the original RaiseMan example (by setting sort key to personName in the attribute inspector for the column)
The sorting then works as expected and my method described above is getting called (NSLog is producing the expected output) suggesting that my sorting code is functional.