我该如何排序NSMutableArray iphone?

时间:2011-07-27 19:45:14

标签: ios objective-c json ios4 nsmutablearray

我有一个场景,应用程序从json php检索信息到NSMutableArray。我的问题如下;我如何通过“时间”字段对元素进行排序?另外,我怎样才能只显示“day”作为“星期一”的元素? (if语句会是什么样子?)。感谢您的帮助。

NSMutableArray中的信息如下所示;

   Array: (
            {
            Code = 2COS402;
            Core = Yes;
            Credit = 15;
            Day = Monday;
            Facilities = Full;
            Level = 4;
            Module = "Introduction to Computer Programming";
            "Room_Empty" = Yes;
            Teacher = "Mark James";
            Time = "10:45";
            id = 1;
        },
            {
            Code = 2GDP401;
            Core = Yes;
            Credit = 15;
            Day = Monday;
            Facilities = Full;
            Level = 4;
            Module = "Fundamentals of Interactive Games";
            "Room_Empty" = No;
            Teacher = "Will Smith";
            Time = "09:00";
            id = 4;
        },
            {
            Code = 2GDP501;
            Core = Yes;
            Credit = 15;
            Day = Monday;
            Facilities = Full;
            Level = 4;
            Module = "Games Play Design";
            "Room_Empty" = Yes;
            Teacher = "Frank Sinatra";
            Time = "15:00";
            id = 6;
        }
    )

1 个答案:

答案 0 :(得分:1)

您可以查看NSMutableArray的{​​{3}}或sortUsingComparator:种方法。当然,您需要定义自定义NSComparator或实现自定义方法。