Tableview column sorting without bindings

I should be so easy…but if this delegate method is invoked

[code]-(void)tableView:(NSTableView *)tableView sortDescriptorsDidChange:(NSArray *)oldDescriptors
{
NSArray *newDescriptor = [tableView sortDescriptors];

[persons sortUsingDescriptors:newDescriptor];

[tableView reloadData];

}
[/code]
I get the following exception:2012-03-10 15:05:59.955 TableTest[1438:403] -[__NSArrayI sortUsingDescriptors:]: unrecognized selector sent to instance 0x7f8df0517f70 2012-03-10 15:05:59.956 TableTest[1438:403] -[__NSArrayI sortUsingDescriptors:]: unrecognized selector sent to instance 0x7f8df0517f70
persons is an mutable array filled with instances of the class ESPerson, which has two properties: name (NSString) and age(NSInteger)
In the the IB I set the sort key to “name” and the selector to “compare:” etc. for each column.

These methods are implemented:

-(NSInteger)numberOfRowsInTableView:(NSTableView *)tableView; -(NSView *)tableView:(NSTableView *)tableView viewForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row; -(void)tableView:(NSTableView *)tableView sortDescriptorsDidChange:(NSArray *)oldDescriptors;My application delegate works as tableview delegate and datasource - it’s a very simple example, but nevertheless I don’t know what’s going wrong here :frowning:

UPDATE: And now I always run into this bug - I think I will switch back to cell-based tableview for now

I hope someone can give me a hint.

cu
Vertex

P.S.: Where is the best place to post general questions related to Objective-C/Cocoa - I am always unsure where to post it :confused:

Ok, I solved it by myself :smiley:

[code]-(void)tableView:(NSTableView *)tableView sortDescriptorsDidChange:(NSArray *)oldDescriptors
{
NSArray *newDescriptor = [tableView sortDescriptors];

[self setPersons:[[[self persons] sortedArrayUsingDescriptors:newDescriptor] mutableCopy]];

[tableView reloadData];

}[/code]
But nevertheless I would like to know if there is a possibility to avoid that a NSMutableArray ivar (here: persons) become immutable.

Edit: As I already expected, I have made a stupid mistake in the code which initialize the NSMutableArray - its never
a good idea to use a class method of NSArray for that :blush:

cu
Vertex