Iphone 为什么tableviewcell没有被更新?

Iphone 为什么tableviewcell没有被更新?,iphone,objective-c,uitableview,Iphone,Objective C,Uitableview,这是显示信息的第二个选项卡。但当我单击它时,它不会更新,有时它会随机更新。我希望它每次都更新。请不要告诉我使用[self.tableView reloadData];当我单击选项卡栏图标时,我知道它调用了该方法,因此无需重写。此函数是我的ViewDidDisplay。Nslog log正确地给出了更新后的值,因此它不更新表单元格的原因 - (void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; NSString *

这是显示信息的第二个选项卡。但当我单击它时,它不会更新,有时它会随机更新。我希望它每次都更新。请不要告诉我使用[self.tableView reloadData];当我单击选项卡栏图标时,我知道它调用了该方法,因此无需重写。此函数是我的ViewDidDisplay。Nslog log正确地给出了更新后的值,因此它不更新表单元格的原因

- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
NSString *country=[[NSUserDefaults standardUserDefaults]objectForKey:@"namecountry"];
//url's
NSURL *url = [NSURL URLWithString:@"someurl"];
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
[request setPostValue:country forKey:@"c_name"];
[request setRequestMethod:@"POST"];
[request setValidatesSecureCertificate:NO];
[request setDelegate:self];
[request startSynchronous];

NSString *response = [request responseString];
NSLog(@"%@",response);
res=[[response componentsSeparatedByString:@","] retain];
NSLog(@"%@",[res objectAtIndex:18]);
show=[NSString stringWithFormat:@"%@",[res objectAtIndex:18]];
float f=[show floatValue];
show=[NSString stringWithFormat:@"%.2f %%",f];
[show retain];
}

这是我创建单元格的函数,我写cell.detailTextLabel.text=show;所以它可以显示更新值,但正如我说的,它是随机更新还是不随机更新。有人能告诉我问题出在哪里吗?顺便说一句,我现在不使用奇数单元格,它只是一个概念。

此代码没有保留问题,但如果您在刷新单元格时遇到问题,如果是我的代码,我会尝试以下方法:

  • 确认正在调用
    cellforrowatinexpath
  • NSLog()
    [array objectAtIndex:indexath.row]
    的结果分配给标签并确认该值是预期值

  • 此代码没有保留问题,但如果您在单元格刷新方面遇到问题,如果是我的代码,我会尝试以下方法:

  • 确认正在调用
    cellforrowatinexpath
  • NSLog()
    [array objectAtIndex:indexath.row]
    的结果分配给标签并确认该值是预期值

  • 感谢您的检查,您知道为什么每次用户在选项卡栏中选择它时,它都不会更新吗?他们是对的,值会到达cellforrowatindexpath right如果是这样,那么代码没有问题。您需要检查应用程序中的其他位置是否存在此问题。感谢您的检查,您知道为什么每次用户在选项卡栏中选择它时它都不会更新吗?他们是对的,值将显示在cellforrowatindexpath right中如果是这样,则代码没有问题。您需要在应用程序中的其他位置检查该问题。
     - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
    UITableViewCell *cell = nil;
    if (indexPath.row % 2 == 0) {
        // EVEN
        cell = [tableView dequeueReusableCellWithIdentifier:@"EvenCell"];
        if (cell == nil) {
            cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"EvenCell"] autorelease];
            UIView *bg = [[UIView alloc] initWithFrame:cell.frame];
            UIColor *colour = [[UIColor alloc] initWithRed: (208.0/255.f) green: (231.0/255.f) 
                                                      blue: (241.0/255.f) alpha: 1.0];
            bg.backgroundColor = colour; 
            cell.backgroundView = bg;
            cell.textLabel.backgroundColor = bg.backgroundColor;
            [bg release];
            cell.detailTextLabel.backgroundColor=[UIColor clearColor];
            cell.detailTextLabel.text=show;
        }
        cell.textLabel.text = [array objectAtIndex:indexPath.row];
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    
    } else {
        // ODD
    
        cell = [tableView dequeueReusableCellWithIdentifier:@"OddCell"];
        if (cell == nil) {
            cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"OddCell"] autorelease];
            UIView *bg = [[UIView alloc] initWithFrame:cell.frame];
    
            UIColor *colour = [[UIColor alloc] initWithRed: (143.0/255.f) green: (169.0/255.f) 
                                                      blue: (180.0/255.f) alpha: 1.0];
            bg.backgroundColor = colour;
            cell.backgroundView = bg;
            cell.textLabel.backgroundColor = bg.backgroundColor;
            [bg release];
        }
        cell.textLabel.text = [array objectAtIndex:indexPath.row];
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    
    
     } 
     return cell;
    }