RE: Sorting an NSTableView by code
RE: Sorting an NSTableView by code
- Subject: RE: Sorting an NSTableView by code
- From: "Drarok Ithaqua" <email@hidden>
- Date: Fri, 30 Jun 2006 11:52:14 +0100
- Importance: Normal
D'oh, it doesn't work as I thought it did.
I read somewhere about setting the key against the TableView's Column, and
using that to sort.
But in reality I just use the key in the Controller, and the view does it's
magic!
I guess I'm just getting tripped up by the MVC paradigm.
One thing I think I'm doing wrong is when I've applied a filter and an order
to the controller,
And I want to find out the next item in the array. I'm doing something like
the following:
<snip>
NSArray *contentArray = [trackController content];
If ([trackController filterPredicate] != nil)
contentArray = [contentArray
filteredArrayUsingPredicate:[trackController filterPredicate]];
If ([trackController sortDescriptors] != nil)
contentArray = [contentArray
sortedArrayUsingDescriptors:[trackController sortDescriptors]];
int currentIndex = [contentArray indexOfObject:currentTrack];
currentTrack = [contentArray objectAtIndex:currentIndex+1];
</snip>
Surely this can't be the right way to do things?
I can't see a simple call to get the filtered, sorted array from the
controller.
Oh, and you can safely ignore any typos in the code above, I'm having to
type it up on my work machine,
by reading it off my laptop. Stupid rules say I can't connect it to the LAN,
in case of viruses etc.
-----Original Message-----
From: Matt Neuburg [mailto:email@hidden]
Sent: 30 June 2006 02:20
To: Drarok Ithaqua
Cc: email@hidden
Subject: 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:
This email sent to email@hidden