Re: Multiple NSSortDescriptors on NSTableColumn header click
Re: Multiple NSSortDescriptors on NSTableColumn header click
- Subject: Re: Multiple NSSortDescriptors on NSTableColumn header click
- From: Sebastian Morsch <email@hidden>
- Date: Sat, 15 Oct 2005 01:01:03 +0200
Solved my own question.
I subclassed NSTableView and overrode setSortDescriptors: to add sort
descriptors for cd number and track number if the album sort
descriptor is the topmost in the array. this way the table isn't
sorted twice anymore as it did when
tableView:sortDescriptorsDidChange: added the new descriptors:
- (void)setSortDescriptors:(NSArray *)array
{
NSMutableArray *newArray = [NSMutableArray array];
// add the set of album, cd number and track number sort
descriptors, with the right sort order
BOOL isAscending = [[array objectAtIndex:0] ascending];
[newArray addObject:[[[NSSortDescriptor alloc]
initWithKey:@"albumName" ascending:isAscending] autorelease]];
[newArray addObject:[[[NSSortDescriptor alloc]
initWithKey:@"cdNumber" ascending:isAscending] autorelease]];
[newArray addObject:[[[NSSortDescriptor alloc]
initWithKey:@"trackNumber" ascending:isAscending] autorelease]];
// keep all sort descriptors from the old array except album, cd
number and track number
NSSortDescriptor *sortDescriptor;
NSEnumerator *enumerator = [array objectEnumerator];
while (sortDescriptor = [enumerator nextObject]) {
if (([[sortDescriptor key] isEqual:@"albumName"] ||
[[sortDescriptor key] isEqual:@"cdNumber"] ||
[[sortDescriptor key] isEqual:@"trackNumber"]) == NO)
{
[newArray addObject:sortDescriptor];
}
}
// finally, set the new sort descriptors
[super setSortDescriptors:newArray];
}
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden