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

Re: Problem with NSSortDescriptor sorting NSMutableArray?


  • Subject: Re: Problem with NSSortDescriptor sorting NSMutableArray?
  • From: Ryan Bates <email@hidden>
  • Date: Mon, 16 Feb 2004 18:56:52 -0800

On Feb 16, 2004, at 6:24 PM, Peter Dean wrote:
[arrayOfRecords sortedArrayUsingDescriptors:[NSArray arrayWithObjects: countryDescriptor,provenceDescriptor,cityDescriptor,nil]];

The "sortedArrayUsingDescriptors:" method returns a new array that is sorted, it does not sort the called array. Try "sortUsingDescriptors:" instead.

Ryan

On Feb 16, 2004, at 6:24 PM, Peter Dean wrote:

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.
_______________________________________________
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.

References: 
 >Problem with NSSortDescriptor sorting NSMutableArray? (From: Peter Dean <email@hidden>)

  • Prev by Date: NSRunAlertPanel-not working?
  • Next by Date: Re: NSTableView/NSPopUpButtonCell Mysteries
  • Previous by thread: Problem with NSSortDescriptor sorting NSMutableArray?
  • Next by thread: NSRunAlertPanel-not working?
  • Index(es):
    • Date
    • Thread