【发布时间】:2014-02-26 00:40:46
【问题描述】:
我有 JSON 文件,我把谁的信息放在我的表中。我有一个用于排序数组的按钮
我可以对数组进行排序并使用NSLog 打印它。如何根据排序后的数组更新表格?
这是我的代码:
-(void)sortArry:(UIButton *)sender
{
NSSortDescriptor *ageDescriptor = [[NSSortDescriptor alloc] initWithKey:@"name" ascending:YES];
NSArray *sortDescriptors = @[ageDescriptor];
NSArray *sortedArray = [tableData sortedArrayUsingDescriptors:sortDescriptors];
//here i have my data in nslog
NSLog(@"%@ sort test",sortedArray);
}
如何在表格中显示我的 sortedArray?
我也用过
[self.tableView reloadData];
排序后没有显示排序后的表格
更新:
这是我的 cellForRowAtIndexPath
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath
*)indexPath
{
static NSString *CellIdentifier = @"Cell";
CustomCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
NSArray *objects = [[NSBundle mainBundle] loadNibNamed:@"CustomCell" owner:nil options:nil];
for (id currentObject in objects)
{
if([currentObject isKindOfClass:[UITableViewCell class]])
{
cell = (CustomCell *) currentObject;
break;
}
}
}
id keyValuePair;
if (tableView == self.searchDisplayController.searchResultsTableView)
{
keyValuePair = [self.filteredTableData objectAtIndex:indexPath.row];
}
else
{
keyValuePair = [self.tableData objectAtIndex:indexPath.row];
}
cell.name.text = keyValuePair[@"name"];
return cell;
}
【问题讨论】:
标签: objective-c json uitableview nsarray nssortdescriptor