2017-06-12 185 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