Objective c 基于数组更新UITableView

Objective c 基于数组更新UITableView,objective-c,json,uitableview,nsarray,nssortdescriptor,Objective C,Json,Uitableview,Nsarray,Nssortdescriptor,我把JSON文件中的信息放在我的表中。我有一个用于排序数组的按钮 我可以对阵列进行排序并使用NSLog打印它。如何根据已排序的数组更新表 这是我的代码: -(void)sortArry:(UIButton *)sender { NSSortDescriptor *ageDescriptor = [[NSSortDescriptor alloc] initWithKey:@"name" ascending:YES]; NSArray *sortDescriptors = @[ag

我把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);
} 
我怎样才能在桌子上展示我的朋友Darray

我也用过

 [self.tableView reloadData];
排序后,但未显示已排序的表

更新:

这是我的手机号码

 - (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;
}
调用[tableView重载数据];数组排序后。

SortDarray需要是viewController的属性,而不是SortAry的实例变量,因此在重新加载所有UITableViewdelegate时,方法可以访问其值并进行更新

更改方法签名以返回已排序的数组

-(NSArray *)sortArry
{

    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);

   return sortedArray;
}
将返回值存储在数据源中:

ArrayDataSource = [self.ArrayDataSource];
最后重新加载表

[self.tableView reloadData];

SortArray在sortary:方法结束时超出范围时被删除。您需要设置UITableViewDelegate方法检查的属性或实例变量。

谢谢您的回答。我想在我单击按钮时让所有这些人员都在我的按钮中,然后对我的表进行排序,如果您发布cellForRowAtIndexPath:method。非常感谢,我用cellforrowatinexpath更新了我的问题:methodAdd self.tableData=sortedArray;在调用reloadData.but tableData是NSMultipleArray但sortedArray是NSArray之前,我可以这样做吗?使用self.tableData=[sortedArray mutableCopy];
[self.tableView reloadData];