Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Sorting an NSTableView by code



On Fri, 30 Jun 2006 00:35:56 +0100, Drarok Ithaqua <email@hidden> said:
>I've tried the following (and variants similar to the following) to
>no avail:
>
> NSSortDescriptor* sorter = [[NSSortDescriptor alloc]
>initWithKey:@"tvcArtist" ascending:YES];
> [trackController setSortDescriptors:[NSArray arrayWithObject:sorter]];

You're doing it right. It is easy to confirm this with a tiny project
consisting of nothing more than this code:

- (void) awakeFromNib {
    NSMutableArray* arr = [[NSMutableArray alloc] initWithCapacity: 3];
    [arr addObject: [NSMutableDictionary dictionaryWithObject:@"Mannie"
forKey:@"tvcArtist"]];
    [arr addObject: [NSMutableDictionary dictionaryWithObject:@"Moe"
forKey:@"tvcArtist"]];
    [arr addObject: [NSMutableDictionary dictionaryWithObject:@"Jack"
forKey:@"tvcArtist"]];
    [trackController setContent: arr];
}

- (void) doSort {
    NSSortDescriptor* sorter = [[NSSortDescriptor alloc]
initWithKey:@"tvcArtist" ascending:YES];
    [trackController setSortDescriptors:[NSArray arrayWithObject:sorter]];
}

This is always the way to track these things down. Try it on a minimal
project. If it works there and doesn't work in your real project, you must
be doing something in the real project to screw things up. Now all you have
to do is figure out what it is. :)

m.



-- 
matt neuburg, phd = email@hidden, <http://www.tidbits.com/matt/>
A fool + a tool + an autorelease pool = cool!
AppleScript: the Definitive Guide - Second Edition!
<http://www.amazon.com/gp/product/0596102119>



 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/email@hidden

This email sent to email@hidden



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.