您好,登錄后才能下訂單哦!
//排序 對時間進行排序
NSMutableArray *dataArray=[[NSMutableArray alloc]initWithCapacity:0];
NSMutableDictionary *dir=[[NSMutableDictionary alloc]init];
[dir setObject:@"2012-12-02" forKey:@"time"];
[dataArray addObject:dir];
[dir release];
NSMutableDictionary *dir1=[[NSMutableDictionary alloc]init];
[dir1 setObject:@"2012-02-15" forKey:@"time"];
[dataArray addObject:dir1];
[dir1 release];
NSMutableDictionary *dir2=[[NSMutableDictionary alloc]init];
[dir2 setObject:@"2012-03-02" forKey:@"time"];
[dataArray addObject:dir2];
[dir2 release];
NSMutableDictionary *dir3=[[NSMutableDictionary alloc]init];
[dir3 setObject:@"2000-03-02" forKey:@"time"];
[dataArray addObject:dir3];
[dir3 release];
NSMutableDictionary *dir4=[[NSMutableDictionary alloc]init];
[dir4 setObject:@"2112-03-02" forKey:@"time"];
[dataArray addObject:dir4];
[dir4 release];
NSMutableArray *myArray=[[NSMutableArray alloc]initWithCapacity:0];
[myArray addObjectsFromArray:dataArray];
//[myArray release];
[dataArray release];
for (int i=0; i<[myArray count]; i++) {
NSLog(@"排序前----->>%@",[[myArray objectAtIndex:i] objectForKey:@"time"]);
}
NSSortDescriptor*sorter=[[NSSortDescriptor alloc]initWithKey:@"time" ascending:YES];
NSMutableArray *sortDescriptors=[[NSMutableArray alloc]initWithObjects:&sorter count:1];
NSArray *sortArray=[myArray sortedArrayUsingDescriptors:sortDescriptors];
[sorter release];
for (int i=0; i<[sortArray count]; i++) {
NSLog(@"排序后----->>%@",[[sortArray objectAtIndex:i] objectForKey:@"time"]);
}
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。