我想排序为NSMutableArray,其结构类似这样,

对象1:NSMutableDictionary

   Affiliation = 2165;
   CallLetters = abc;
   Channel = "2.1";

   ChannelLocation = "";
   ChannelSchedules =         (
   );
   DisplayName = abc;
   DvbTriplets =         (
   );
   FullName = "bc";
   IconAvailable = 1;
   Order = 1;
   ParentNetworkId = 2;
   ServiceType = Digital;
   SourceAttributeTypes =
       HD

   SourceId = 11222;
   SourceType = Broadcast;
   TiVoSupported = 1;
   Type = "24-Hours";


对象2:NSMutableDictionary

   Affiliation = 1209;
   CallLetters = "xyz";
   Chann?el = "4.1";

   ChannelLocation = "";
   ChannelSchedules =         (
   );
   DisplayName = "xyz";
   DvbTriplets =         (
   );
   FullName = "xyz";
   IconAvailable = 1;
   Order = 2;
   ParentNetworkId = 5;
   ServiceType = Digital;
   SourceAttributeTypes = HD

   SourceId = 111
   SourceType = Broadcast;
   TiVoSupported = 1;
   Type = "24-Hours";
   VirtualChannelNumber = "4.1";


...
..



./

数组包含许多对象,而这些对象包含许多字典。我希望能够使用NSMutableDictionary键“ Channel”以升序排列上述数组?

如何排序数组?

最佳答案

使用NSSortDescriptor它将起作用

    NSSortDescriptor *aSortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"Channel" ascending:YES];
   [yourarrayobject sortUsingDescriptors:[NSArray arrayWithObject:aSortDescriptor]];
    [aSortDescriptor release];

10-08 05:50
查看更多