问题描述
我有一个 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:
和 .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
进行排序,请使用,
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按字母顺序排序字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!