2014-09-23 57 views
0

我在单元格中有一个标签,我想用我解析的JSON数组中的数据进行更新。问题是获取数据后标签是空白的,并且只会在上下滚动tableview后才会显示。我试图强制重新加载视图[self.view setNeedsDisplay];,它仍然无法正常工作。我如何解决这个问题?单元格中的UILabel仅在滚动上下后显示

下面是一些意见的代码片段在里面:

@implementation outletView 
@synthesize outletInfo; 

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    ... 
    // Do any additional setup after loading the view. 
    [[AFHTTPRequestOperationManager manager] GET:[SERVER_URL stringByAppendingString:@"api/points"] parameters:[NSDictionary dictionaryWithObjectsAndKeys:[[NSUserDefaults standardUserDefaults] objectForKey:@"authToken"],@"auth_token",nil] success:^(AFHTTPRequestOperation *operation, id responseObject) { 
     NSString *outletID = [[outletInfo valueForKeyPath:@"preference"] objectForKey:@"outlet_id"]; 
     NSArray *outletArray = (NSArray*)responseObject; 
     NSLog(@"array: %@", outletArray); 
     for(NSDictionary *diction in outletArray) { 
      NSString *dictionID = [diction objectForKey:@"outlet_id"]; 
      if ([dictionID isEqualToString:outletID]) { 
       pointOutlet = [diction objectForKey:@"total"]; 
      } 
     }   
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) { 
     NSLog(@"Error : %@",[error description]); 
    }]; 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    NSString *CellIdentifier = indexPath.section==0 ? @"outletViewCell" : @"categoryCell"; 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 

    // Here is the cell 
    if(indexPath.section==0){ 
     [cell setSelectionStyle:UITableViewCellSelectionStyleNone]; 
     [(UIImageView *)[cell viewWithTag:1] sd_setImageWithURL:[NSURL URLWithString:outletInfo[@"backgroundImageUrl"]] placeholderImage:nil]; 
     [(UIImageView *)[cell viewWithTag:2] sd_setImageWithURL:[NSURL URLWithString:outletInfo[@"logoUrl"]] placeholderImage:nil]; 
     [(UILabel *)[cell viewWithTag:3] setText:outletInfo[@"name"]]; 
     [(UILabel *)[cell viewWithTag:4] setText:outletInfo[@"address"]]; 

     //Here is the UILabel that I want to update 
     [(UILabel *)[cell viewWithTag:6] setText:pointOutlet]; 
    } else { 
     ... 
    } 
    return cell; 
} 
@end 
+0

从TableView中 – Rajesh 2014-09-23 05:03:48

+0

的所有者重新加载表尝试重新加载乌尔的tableview [self.tableView ReloadData]; – sanjeet 2014-09-23 05:08:20

回答

1

做如下修改: -

[[AFHTTPRequestOperationManager manager] GET:[SERVER_URL stringByAppendingString:@"api/points"] parameters:[NSDictionary dictionaryWithObjectsAndKeys:[[NSUserDefaults standardUserDefaults] objectForKey:@"authToken"],@"auth_token",nil] success:^(AFHTTPRequestOperation *operation, id responseObject) { 
    NSString *outletID = [[outletInfo valueForKeyPath:@"preference"] objectForKey:@"outlet_id"]; 
    NSArray *outletArray = (NSArray*)responseObject; 
    NSLog(@"array: %@", outletArray); 
    for(NSDictionary *diction in outletArray) { 
     NSString *dictionID = [diction objectForKey:@"outlet_id"]; 
     if ([dictionID isEqualToString:outletID]) { 
      pointOutlet = [diction objectForKey:@"total"]; 
     } 
    } 
     //Here you need to call tableView reload. This will reload your tableView and show the label. 
     [tableView reload];  

} failure:^(AFHTTPRequestOperation *operation, NSError *error) { 
    NSLog(@"Error : %@",[error description]); 
}]; 
+0

感谢您的支持。我其实只需要这样做。 '[infoTable reloadData]'。虽然我不认为我的解决方案很干净。 :) – 2014-09-23 06:33:50

0

刷新当您解析响应主线程在桌子上。

dispatch_async(dispatch_get_main_queue(), ^{ 
    }); 

重新载入此块的表格。

0

这种问题出现在数据未到并且您的tableView方法调用之前,在从服务器获取所有数据后重新载入您的表视图。

相关问题