• 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
Problem with NSSortDescriptor sorting NSMutableArray?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Problem with NSSortDescriptor sorting NSMutableArray?


  • Subject: Problem with NSSortDescriptor sorting NSMutableArray?
  • From: Peter Dean <email@hidden>
  • Date: Tue, 17 Feb 2004 13:24:17 +1100

I have an NSMutableArray which contains an array of objects, of which is displayed through NSTableView. My desire is to make use of the NSSortDescriptor for sorting, which I have not been successful is returning a sorted array - even though I have been successful with the selector method, the NSSortDescriptor has become a bit of a Nemesis that I now need to overcome.

I have been trying various snipets of code through books, mailling-lists, FAQ, sample code, and nearly all refer to the selector methods, which now brings me to the maillist list forum.

Please find below a snipet of my MyDataSource.m code, it compiles and when run, it appears to be doing something in when the table header is clicked upon, but unfortunately doesn't display a sorted list, unlike utilising the selector method.

- (void)tableView:(NSTableView *)tableView didClickTableColumn:(NSTableColumn *)tableColumn
{
NSString * identifier = [tableColumn identifier];

if ([identifier isEqualToString:@"country"])
{
// Flip flop the sorting direction
mySortingDirection = !mySortingDirection;

// Set the sorting image
[tableView setIndicatorImage: (mySortingDirection ? [NSImage imageNamed:@"NSAscendingSortIndicator"] : [NSImage imageNamed:@"NSDescendingSortIndicator"]) inTableColumn: tableColumn];

// Define to sorting order - haven't been able to get it to work yet. Only the basic selector method - bugger!!!
NSSortDescriptor * countryDescriptor = [[[NSSortDescriptor alloc] initWithKey:@"country" ascending:mySortingDirection] autorelease];
NSSortDescriptor * provenceDescriptor = [[[NSSortDescriptor alloc] initWithKey:@"provence"ascending:mySortingDirection] autorelease];
NSSortDescriptor * cityDescriptor = [[[NSSortDescriptor alloc] initWithKey:@"city" ascending:mySortingDirection] autorelease];

// Perform the sort
//[arrayOfRecords sortUsingSelector:@selector(customComparison:)];
[arrayOfRecords sortedArrayUsingDescriptors:[NSArray arrayWithObjects: countryDescriptor,provenceDescriptor,cityDescriptor,nil]];

// Refresh
[tableView reloadData];
}
}

Look forward to your assistance,

Peter J. Dean
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

  • Follow-Ups:
    • Re: Problem with NSSortDescriptor sorting NSMutableArray?
      • From: Ryan Bates <email@hidden>
  • Prev by Date: Re: Apps whitout nib
  • Next by Date: Re: makeKeyAndOrderFront and NSBorderlessWindowMask
  • Previous by thread: Re: Installer framework or .pkg format?
  • Next by thread: Re: Problem with NSSortDescriptor sorting NSMutableArray?
  • Index(es):
    • Date
    • Thread