Sorting one column table?

  • I'm testing sorting a table using datasource. When I did it with a table with two columns all went well. I was using

    - (void)tableView:(NSTableView *)aTableView
                  sortDescriptorsDidChange:(NSArray *)oldDescriptors
        NSArray *newDescriptors = [aTableView sortDescriptors];
        [books sortUsingDescriptors:newDescriptors];
        [aTableView reloadData];

    However when I tried with a table consisting of one column I got following error message

    [<NSCFString 0x2d00c> valueForUndefinedKey:]: this class is not key value coding-compliant for the key title.

    When I used two columns I had a mutable array books, consisting of book objects, where a book object consisted of a title and an author. So I had key value coding-compliant getters and setters for them.

    However for one column table there is no need to have a special Book class, since each book is identified by its title only. So my mutable array consists of NSStrings where each string is a title of a book. So there is no need to have setters and getters. And that seems to prevent sorting using the tableView:sortDescriptorsDidChange: method.

    So my question is, how do I introduce sorting for one column table.


    Shape Yahoo! in your own image.  Join our Network Research Panel today!
  • On 2007 Oct, 02, at 12:56, Bob Ueland wrote:

    > So my question is, how do I introduce sorting for one column table.

    NSSortDescriptor requires that the referenced property keys be KVC.
    Use your Book class.
previous month october 2007 next month
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31        
Go to today