2013-01-08 56 views

回答

2

這是一種使用任何類型的對象(使用塊)對任何NSArray進行排序的非常通用的方法。現在,它只是被指定爲當前與NSDate對象相關的問題的解決方案。

NSArray *_arrayOfDates = // your array with the NSDate objects; 
NSArray *_sortedArrayOfDates = [_arrayOfDates sortedArrayUsingComparator:^NSComparisonResult(id obj1, id obj2) { 
    return [((NSDate *) obj1) compare:((NSDate *)obj2)]; 
}]; 
NSLog(@"%@", _sortedArrayOfDates); 

請注意:可以使用NSMutableArray-sortUsingComparator:方法,它提供了相同的結果,但該數組將自身內部進行排序。

1

數組試試這個:

  NSLog(@"livevideoparsingarray..%@",livevideoparsingarray); 
      NSSortDescriptor * descLastname = [[NSSortDescriptor alloc] initWithKey:@"active" ascending:YES]; 
      [livevideoparsingarray sortUsingDescriptors:[NSArray arrayWithObjects:descLastname, nil]]; 
      [descLastname release]; 
      videoparsing = [livevideoparsingarray copy]; 

livevideoparsingarray是我的數組我有&活動是我的標籤,這是我排序的數組。你改變你的要求。

相關問題