2016-04-25 9 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を使用したい場合は、その後

、同じよう viewDidloadheightForRowAtIndexPath .doということで、それを返しません。
tableView.estimatedRowHeight = 100.0 
tableView.rowHeight = UITableViewAutomaticDimension 

UITableViewAutomaticDimensionにはautolayoutが必須で、適切な制約が設定されていることを確認してください。必要に応じてすべてのjsonデータを正常に取得したら、テーブルのデータをリロードします。

これが役に立ちます。

関連する問題