我有一个 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 =developer.apple/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSArray_Class/NSArray.html#//apple_ref/doc/uid/20000137-BABBHAGJ> sortedArrayUsingSelector: 和 localizedCaseInsensitiveCompare: / 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按字母顺序排序字符串?
发布评论