• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NSTableView, NSArrayController and secondary sortings
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSTableView, NSArrayController and secondary sortings


  • Subject: Re: NSTableView, NSArrayController and secondary sortings
  • From: mmalc crawford <email@hidden>
  • Date: Sun, 9 Dec 2007 10:51:40 -0800


On Dec 8, 2007, at 8:00 AM, Adhamh Findlay wrote:

I have an NSTableView that is bound to an NSArrayController. There are 5 columns in the table view, one of which is an NSDate. What I would like to do is always have the secondary sort be the date column.

Taking this literally (i.e. it doesn't matter what other sorting there is, the date sort should always be second), you can create a subclass of NSArrayController that adds a date sort descriptor in the correct place, along the lines of the example shown below.

mmalc



@interface SortByDate2ArrayController : NSArrayController
{
    NSMutableArray *sortDescriptors;
}
@end


@implementation SortByDate2ArrayController


- (NSArray *)sortDescriptors { return sortDescriptors; }


- (void)setSortDescriptors:(NSArray *)newDescriptors { if (sortDescriptors == newDescriptors) { return; }

    [sortDescriptors release];

    sortDescriptors = [newDescriptors mutableCopy];
    NSSortDescriptor *dateDescriptor = nil;

    for (NSSortDescriptor *descriptor in newDescriptors)
    {
        if ([[descriptor key] isEqualToString:@"date"])
        {
            dateDescriptor = descriptor;
            [sortDescriptors removeObject:descriptor];
        }
    }

if (dateDescriptor == nil)
{
dateDescriptor = [[[NSSortDescriptor alloc] initWithKey:@"date" ascending:YES] autorelease];
}


    NSInteger dateIndex = 1;
    if ([sortDescriptors count] == 0)
    {
        dateIndex = 0;
    }

    [sortDescriptors insertObject:dateDescriptor atIndex:dateIndex];
    [self rearrangeObjects];
}


@end

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >NSTableView, NSArrayController and secondary sortings (From: Adhamh Findlay <email@hidden>)

  • Prev by Date: Re: Newbie: compare version string
  • Next by Date: NSOutlineView expansion limit
  • Previous by thread: Re: NSTableView, NSArrayController and secondary sortings
  • Next by thread: Re: NSTableView, NSArrayController and secondary sortings
  • Index(es):
    • Date
    • Thread