如何按升序排序NSMutableArray,iPhone? [英] How to sort NSMutableArray in ascending order, iPhone?

查看:93
本文介绍了如何按升序排序NSMutableArray,iPhone?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆