2014-09-23 55 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方法調用之前,在從服務器獲取所有數據後重新載入您的表視圖。

相關問題