NSMutableArray 排序
NSMutableArray *array=[[NSMutableArray alloc] initWithCapacity:11];
NSMutableDictionary *dir6=[[NSMutableDictionary alloc] initWithCapacity:1];
[dir6 setObject:@"曹磊" forKey:@"FriendName"];
[dir6 setObject:@"曹磊" forKey:@"FriendID"];
[array addObject:dir6];
NSMutableDictionary *dir=[[NSMutableDictionary alloc] initWithCapacity:1];
[dir setObject:@"王均" forKey:@"FriendName"];
[dir setObject:@"曹磊" forKey:@"FriendID"];
[array addObject:dir];
NSMutableDictionary *dir1=[[NSMutableDictionary alloc] initWithCapacity:1];
[dir1 setObject:@"111" forKey:@"FriendName"];
[dir1 setObject:@"曹磊" forKey:@"FriendID"];
[array addObject:dir1];
NSMutableDictionary *dir2=[[NSMutableDictionary alloc] initWithCapacity:1];
[dir2 setObject:@"王興朝" forKey:@"FriendName"];
[dir2 setObject:@"曹磊" forKey:@"FriendID"];
[array addObject:dir2];
NSMutableDictionary *dir3=[[NSMutableDictionary alloc] initWithCapacity:1];
[dir3 setObject:@"wangjun" forKey:@"FriendName"];
[dir3 setObject:@"曹磊" forKey:@"FriendID"];
[array addObject:dir3];
NSMutableDictionary *dir4=[[NSMutableDictionary alloc] initWithCapacity:1];
[dir4 setObject:@"apk" forKey:@"FriendName"];
[dir4 setObject:@"曹磊" forKey:@"FriendID"];
[array addObject:dir4];
NSLog(@">>>>>>排序前>>>>>>>>");
for (int i=0; i<[array count]; i++) {
NSLog(@"%@",[[array objectAtIndex:i] objectForKey:@"FriendName"]);
}
NSSortDescriptor *sorter = [[NSSortDescriptor alloc] initWithKey:@"FriendName" ascending:YES];
NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:&sorter count:1];
NSArray *sortedArray = [array sortedArrayUsingDescriptors:sortDescriptors];
NSLog(@"\n\n\n\n\n>>>>>>排序後>>>>>>>>");
for (int i=0; i<[sortedArray count]; i++) {
NSLog(@"%@",[[sortedArray objectAtIndex:i] objectForKey:@"FriendName"]);
}
留言
張貼留言