Ios 更新自定义单元格中的UILabel文本

Ios 更新自定义单元格中的UILabel文本,ios,json,uitableview,Ios,Json,Uitableview,在我的UITableViewController中,有从JSON填充的自定义单元格。每个单元格都有一个显示文本值的ui标签(@“valoracion”)。当用户选择行时,将显示单元对象的详细视图。在此详细视图中,用户可以更改valoracion的值。如果用户返回到UITableViewController,valoracion应显示新值,但实际上它显示旧值 当用户从详细视图返回到UITableViewController时,如何更新UITableViewController中的valoracio

在我的UITableViewController中,有从JSON填充的自定义单元格。每个单元格都有一个显示文本值的
ui标签(
@“valoracion”
)。当用户选择行时,将显示单元对象的详细视图。在此详细视图中,用户可以更改
valoracion
的值。如果用户返回到
UITableViewController
valoracion
应显示新值,但实际上它显示旧值

当用户从详细视图返回到
UITableViewController
时,如何更新
UITableViewController
中的
valoracion

更新***

内部视图加载方法:

//URL definition where php file is hosted

    int categoriaID = [[categoriaDescription objectForKey:@"idCategoria"] intValue];

    NSString *string = [NSString stringWithFormat:@"%d", categoriaID];
    NSLog(@"CATEGORIA ID STGRING %@",string);
    NSMutableString *ms = [[NSMutableString alloc] initWithString:@"http://mujercanariasigloxxi.appgestion.eu/app_php_files/empresaslist.php?id="];
    [ms appendString:string];
    // URL request
    NSLog(@"URL = %@",ms);
   NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:ms]];
    //URL connection to the internet
    [[NSURLConnection alloc]initWithRequest:request delegate:self];
现在是JSON委托方法和didSelecRowAtIndexpath方法:

//methods to perform the connection and population of data

-(void)connection: (NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{

    data = [[NSMutableData alloc]init];

}

-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)thedata
{
    [data appendData:thedata];
}
-(void)connectionDidFinishLoading:(NSURLConnection *)connection
{
    //if data received network indicator not visible
    [UIApplication sharedApplication].networkActivityIndicatorVisible=NO;

    //array waterfalls populated via JSON from database
    categorias = [NSJSONSerialization JSONObjectWithData:data options:nil error:nil];
    NSLog(@"THE DA TA &@",categorias);
    [self.tableView reloadData];
}

//only in case of error
-(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
{
    UIAlertView *errorView = [[UIAlertView alloc]initWithTitle:@"Error" message:@"The download could not complete - please make sure you are connected to eithre 3G or WiFi" delegate:nil cancelButtonTitle:@"Dismiss" otherButtonTitles:nil];
    [errorView show];
    //if no connection network indicator not visible
    [UIApplication sharedApplication].networkActivityIndicatorVisible=NO;

}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    DetalleEmpresaViewController *detailViewController =[self.storyboard instantiateViewControllerWithIdentifier:@"detailEmpresaViewController"];
    detailViewController.title =[[categorias objectAtIndex:indexPath.row]objectForKey:@"idCategoria"];
    detailViewController.detalleDescription = [categorias objectAtIndex:indexPath.row];
    [self.navigationController pushViewController:detailViewController animated:YES];
}

尝试调用
[tableview reloadData]
方法,并确保tableview委托方法的实现是正确的


如果更改和保存JSON的位置是另一个,而不是
tableViewController
,则将
reloadData
方法放入
tableViewController
类的
viewdide
。如果您在相同的
tableViewController
的其他方法中保存JSON,则将
reloadData
放在该方法的最后一行。

是否重新加载表数据?发布您的代码将有助于了解您做了什么/没有做什么。@BenAvery,我仅在JSON委托方法之后重新加载数据。您应该在用户更改文本值@“valoracion”或关闭查看的详细信息后重新加载数据。@BenAvery,我已更新了我的问题,包括CellForRowatineXpath方法OK。我看你有一大堆字典。尝试只放置[self.tableView reloadData];在
viewdide
方法中。我正在通过JSON填充数据,在您更改并保存JSON文件或字符串或它是什么之后,我应该将重新加载数据放在哪里@如果您展示了
UITableViewController
类实现的一些代码,MVA将更容易为您提供帮助。方法lile
cellForRow
等。我将更新我的问题,包括cellforrowatinexpath方法。以及更改和保存JSON的方法。这些方法属于同一个控制器吗?如果没有,请注意它们的层次结构@mvasco
//methods to perform the connection and population of data

-(void)connection: (NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{

    data = [[NSMutableData alloc]init];

}

-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)thedata
{
    [data appendData:thedata];
}
-(void)connectionDidFinishLoading:(NSURLConnection *)connection
{
    //if data received network indicator not visible
    [UIApplication sharedApplication].networkActivityIndicatorVisible=NO;

    //array waterfalls populated via JSON from database
    categorias = [NSJSONSerialization JSONObjectWithData:data options:nil error:nil];
    NSLog(@"THE DA TA &@",categorias);
    [self.tableView reloadData];
}

//only in case of error
-(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
{
    UIAlertView *errorView = [[UIAlertView alloc]initWithTitle:@"Error" message:@"The download could not complete - please make sure you are connected to eithre 3G or WiFi" delegate:nil cancelButtonTitle:@"Dismiss" otherButtonTitles:nil];
    [errorView show];
    //if no connection network indicator not visible
    [UIApplication sharedApplication].networkActivityIndicatorVisible=NO;

}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    DetalleEmpresaViewController *detailViewController =[self.storyboard instantiateViewControllerWithIdentifier:@"detailEmpresaViewController"];
    detailViewController.title =[[categorias objectAtIndex:indexPath.row]objectForKey:@"idCategoria"];
    detailViewController.detalleDescription = [categorias objectAtIndex:indexPath.row];
    [self.navigationController pushViewController:detailViewController animated:YES];
}