Jacky
Jacky

Reputation: 1

NSFetchedResultController Sorting problem

I would like to sort the nsarray record as the following:

NSArray * name = [entityArray valueForKey:@"Name"];  

using NSSortDescriptor , but it does not show ascending.

Upvotes: 0

Views: 97

Answers (2)

user745098
user745098

Reputation:

Add the following in your fetch record function.

NSSortDescriptor *sortDescriptor = [NSSortDescriptor sortDescriptorWithKey:@"column2sort" ascending:YES];   
NSArray *sortDescriptorArray = [NSArray arrayWithObjects: sortDescriptor, nil];
[fetchRequest setSortDescriptors:sortDescriptorArray];

Upvotes: 1

Narayanan Ramamoorthy
Narayanan Ramamoorthy

Reputation: 826

NSSortDescriptor *lastNameDescriptor = [[NSSortDescriptor alloc] initWithKey:@"CompanyName" ascending:YES selector:@selector(caseInsensitiveCompare:)] ;

[companyListArray sortUsingDescriptors:[NSArray arrayWithObject:lastNameDescriptor]];

[lastNameDescriptor release];

use like this and try

Upvotes: 0

Related Questions