如何在NSMutableArray按字母顺序排序字符串?

编程入门 行业动态 更新时间:2024-10-11 17:20:42
本文介绍了如何在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 =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按字母顺序排序字符串?

本文发布于:2023-11-10 14:22:17,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1575610.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:字符串   字母   顺序   如何在   NSMutableArray

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!