Thursday, December 26, 2013

core data fetch data sorting problem

Want to retrieve data from core data in at a certain order, and then displayed on a table view. In datamodel file defines a named order_id (integer 64) to do this sort of attribute.

Take the time to sort the data set the following code:
 
NSSortDescriptor * sortDescriptor = [[NSSortDescriptor alloc] initWithKey: @ "order_id" ascending: YES];
NSArray * sortDescriptors = [[NSArray alloc] initWithObjects: sortDescriptor, nil];
[FetchRequest setSortDescriptors: sortDescriptors];

[SortDescriptor release];
[SortDescriptors release];


But found not in accordance with the specified data extracted arranged in order, for example, I insert some data, to set them order_id are 1,2,3,4,5;
They also hope that when displayed in that order to render, but now sort the chaos, so the order of the content displayed in the table view into chaos.

I found my original order_id data are 1,2,3,4,5; But after inserting the core data, I print it out so that it becomes the following:
100753152,
101028112,
100808672,
101050848,
101052880

Are not small to large data when such data if taken by order_id sort do not do right.

I also used to test other fields such sort, such as: string type display_name, sort test results are correct.
Is not the core data in NSNumber type of data sorting a problem? Seeking advice. Thank you
Reply:
Nobody knows? Help Ha! !

No comments:

Post a Comment