2014-04-05 85 views
-1
self.objectSet = [NSMutableArray array]; 

//add objects to set 

[self.objectSet sortUsingComparator:^NSComparisonResult(id a, id b) { 
    NSDate *firstDate = [(Entity *)a createdAt]; 
    NSDate *secondDate = [(Entity *)b createdAt]; 
    return [secondDate compare:firstDate]; 
}]; 

我想通過createdAt日期對nsmutablearray進行排序。但是,上述代碼對顯示的表格視圖沒有影響。數據未排序。按日期排序對象的NSMutableArray

任何想法最新怎麼了?

+1

我猜「createdAt」不是正確的屬性名稱,或者還有其他原因,爲什麼你的日期回來零。 –

+0

@HotLicks你是對的,PLZ發佈這個答案。 –

回答

0

您是否嘗試使用排序描述符進行排序? 它是一樣的效果嗎?

NSSortDescriptor *sortDescriptor = [NSSortDescriptor sortDescriptorWithKey:@"createdAt" ascending:YES]; 
[self.objectSet sortUsingDescriptors:@[sortDescriptor]];