2016-04-25 99 views
0

我想在获取JSON数据后根据内容调整UITableViewCell的高度。获取JSON数据后以编程方式设置UITableViewCell高度

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { 
    return UITableViewAutomaticDimension; 
} 

我已经添加了像这样但UITableViewCell高度不能根据内容增加。请帮我解决。

- (void) getAllocatedJobs { 
    _allTableData = [[NSMutableArray alloc]init]; 
    [SVProgressHUD show]; 
    dispatch_queue_t getInit = dispatch_queue_create("getinit",NULL); 
    dispatch_async(getInit, ^{ 
     NSDictionary *jsonResponse = [commClass getJobs:strDriverId paramJobType:@""]; 
     NSNumber *status = [jsonResponse valueForKey:@"Success"]; 
     NSString *message = [jsonResponse valueForKey:@"Message"]; 
     NSArray *dataArray = [jsonResponse valueForKey:@"lstJob"]; 
     dispatch_async(dispatch_get_main_queue(), ^{ 
      if([status intValue] == 1) { 
       for(int i=0; i<[dataArray count]; i++) { 
        NSDictionary *JobData = [dataArray objectAtIndex:i]; 
       [_allocatedTable reloadData]; 

      } else { 
       [commClass showAlert:APP_NAME alertMessage:message]; 
       [SVProgressHUD dismiss]; 
      } 
     }); 
    }); 
} 

回答

0

尝试基于此方法中的含量计算高度: -

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
1

,如果你想使用UITableViewAutomaticDimension然后在heightForRowAtIndexPathviewDidload不会返回它。做它喜欢,

tableView.estimatedRowHeight = 100.0 
tableView.rowHeight = UITableViewAutomaticDimension 

并且自动布局对于UITableViewAutomaticDimension是必需的,所以请确保您已设置适当的约束。并在需要时成功获取所有json数据后重新载入表数据。

希望这会有所帮助:)

相关问题