2016-04-25 96 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數據後重新載入表數據。

希望這會有所幫助:)

相關問題