2017-06-12 131 views
0

我使用NSSortDescriptor以降序排序存儲在NSArray中的值,並將排序的值顯示在控制檯中。按降序對錶格數據進行排序目標C

但是zhr排序的表數據在重新加載表視圖時沒有排序。

這裏是我的代碼:

NSArray *descriptor = [NSArray arrayWithObject:[[NSSortDescriptor alloc] initWithKey:@"Priority" ascending:NO]]; 
self.searchResult = [self.responseData sortedArrayUsingDescriptors:descriptor]; 
NSLog(@"Sorted Array %@", self.searchResult); 
+0

附加的tableview數據源的方法。 – KKRocks

+0

你可以顯示你的dataSource方法嗎?你應該在那裏使用searchResult。並且一定要在對數組進行排序後調用[tableView reloadData] – iamirzhan

+0

是的,我重新加載了tableview。 [self.taskTableView reloadData]; –

回答

0

試試這個:

NSSortDescriptor *brandDescriptor = [[NSSortDescriptor alloc] initWithKey:@"Priority" ascending:NO]; 
NSArray *sortDescriptors = [NSArray arrayWithObject:brandDescriptor]; 
NSArray *sortedArray = [tripStatusArray sortedArrayUsingDescriptors:sortDescriptors]; 
[yourTableView reloadData]; 

使用sortedArray數據裝載您的tableView。希望這可以幫助。

+0

我試過這種方法,但它沒有加載排序表數據 –

+0

@SherineSJ你重新加載這個方法後的桌面視圖?如果沒有檢查我編輯的答案 – Himanth

+0

是的,我重新加載tableView。我也試過你的編輯答案,它不工作 –

0

試試這個代碼:

NSArray *SortedData = [yourDict or Array allKeys]; 
     NSSortDescriptor* sortOrder = [NSSortDescriptor sortDescriptorWithKey: @"self" ascending: YES]; 
     SortedData = [SortedData sortedArrayUsingDescriptors: [NSArray arrayWithObject: sortOrder]]; 
+0

yourDict是字典還是數組? –

+0

它是一個臨時數組,您必須將您想要排序的數組或字典的值 – Abhi