【问题标题】:How to sort NSMutableArray which contains NSIndexPath integer array?如何对包含 NSIndexPath 整数数组的 NSMutableArray 进行排序?
【发布时间】:2013-07-04 05:52:55
【问题描述】:

我有一个NSMutableArray

它包含NSIndexPaths,它本身就是一个 NSUInteger 数组。

数组长这样

[

 (NSIndexPath xxxxxxx) 3 indexes [1, 0, 0],   
 (NSIndexPath xxxxxxx) 3 indexes [2, 1, 1],  
 (NSIndexPath xxxxxxx) 3 indexes [1, 1, 0],  
 (NSIndexPath xxxxxxx) 3 indexes [1, 0, 1],

。 .

]

现在我想根据NSIndexPath 整数数组值对NSMutableArray 进行排序。结果应该是这样的。

[

(NSIndexPath xxxxxxx) 3 indexes [1, 0, 0],  
(NSIndexPath xxxxxxx) 3 indexes [1, 0, 1],   
(NSIndexPath xxxxxxx) 3 indexes [1, 1, 0],   
(NSIndexPath xxxxxxx) 3 indexes [2, 1, 1],  

..

]

怎么做?

【问题讨论】:

    标签: ios objective-c nsmutablearray nsindexpath


    【解决方案1】:

    假设您的NSMutableArray 被称为indexPaths,您可以这样做:

    [indexPaths sortUsingSelector:@selector(compare:)];
    

    【讨论】:

      【解决方案2】:

      除了 Maddy 的建议之外,您还可以尝试使用自定义 NSSortDescriptor 来应用您想要的特定排序规则。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-11-08
        • 1970-01-01
        • 2019-09-18
        • 1970-01-01
        • 1970-01-01
        • 2016-04-03
        相关资源
        最近更新 更多