问题描述
我有SQLite数据库(DB)并将其作为模型类并在NSMutableArray中获取数据库。我的DB与此DB类似。
StudentName | RegisterNumber | DatesOfJoin(DoJ)
我在tableView中成功显示了DoJ,但我想在tableView中按升序和降序排序DatesOfJoin。
任何帮助将不胜感激,并提前感谢您。
I have SQLite Database(DB) and made this to model class and taken the data of DB in NSMutableArray. My DB is similar to this DB.StudentName | RegisterNumber | DatesOfJoin(DoJ)I am displaying the DoJ in tableView successfully, but I wanna sort the DatesOfJoin in Ascending order and Descending order in tableView.Any help would be appreciated and Thanks you in advance.
推荐答案
您可以使用 NSSortDescriptor
和 sortUsingDescriptors:sortDescriptors
对可变数组进行排序。
You can use NSSortDescriptor
and sortUsingDescriptors:sortDescriptors
to sort a mutable array.
NSSortDescriptor *sortDescriptor;
sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"DatesOfJoin" ascending:YES];
NSArray *sortDescriptors = [NSArray arrayWithObject:sortDescriptor];
[array sortUsingDescriptors:sortDescriptors];
[sortDescriptor release];
这篇关于如何按升序排序NSMutableArray,iPhone?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!