如何在NSMutableArray按字母顺序排序字符串? [英] How can I sort strings in NSMutableArray into alphabetical order?

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

问题描述

我有一个 NSMutableArray 中的字符串列表,我想按字母顺序排序,然后在我的表视图中显示它们。

I have a list of strings in an NSMutableArray, and I want to sort them into alphabetical order before displaying them in my table view.

我如何做到这一点?

推荐答案

有以下Apple的工作示例, href =https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSArray_Class/NSArray.html#//apple_ref/doc/uid/20000137-BABBHAGJ> sortedArrayUsingSelector: localizedCaseInsensitiveCompare: .com / library / mac / documentation / Cocoa / Conceptual / Collections / Articles / Arrays.html#// apple_ref / doc / uid / 20000132-SW8>集合文档:

There is the following Apple's working example, using sortedArrayUsingSelector: and localizedCaseInsensitiveCompare: in the Collections Documentation:

sortedArray = [anArray sortedArrayUsingSelector:
                       @selector(localizedCaseInsensitiveCompare:)];

请注意,这将返回一个新的排序数组。如果您要对 NSMutableArray 进行排序,请使用 sortUsingSelector:

Note that this will return a new sorted array. If you want to sort your NSMutableArray in place, then use sortUsingSelector: instead, like so:

[mutableArray sortUsingSelector:@selector(localizedCaseInsensitiveCompare:)];

这篇关于如何在NSMutableArray按字母顺序排序字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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