2014-11-09 2 views
0

동일한 ViewController에 두 개의 UITableView가 있습니다. 하나는 UILabel 내용 크기를 기반으로 동적 높이를 사용하고 다른 하나는 모든 고정 높이입니다. 태그를 사용하여 두 개의 TableView를 분리했습니다.일부 크기 조정 셀 및 두 개의 UITableViews 일부 고정

self.tableView1.rowHeight = UITableViewAutomaticDimension; 

과 : 나는 이것을 사용하여 시도

- (CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath { 
    if (tableView.tag == 1) { 
     return 114.0f; 
    } else { 
     if (indexPath.section == 0) { 
      return 50.0f; 
     } else if (indexPath.section == 2) { 
      return 20.0f; 
     } else { 
      return 44.0f; 
     } 
    } 
} 

문제는 동적 세포는 동적으로 변경하지 않고 정적 높이 세포는 원래 올바른 높이가 있지만, 그들은보기에서 스크롤 할 때 그런 다음 셀의 기본 높이로 변경됩니다.

아무도 도와 줄 수 있습니까?

답변

0

당신은 구현할 때 :

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath 
{  
if (tableView.tag == 1) { 
    return 114.0f; 
} else { 
    if (indexPath.section == 0) { 
     return 50.0f; 
    } else if (indexPath.section == 2) { 
     return 20.0f; 
    } else { 
     return 44.0f; 
    } 
} 
} 
+0

그러나 경우를 : 당신은 당신의 보호에 이것을 추가, 이것과

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath 

일반적으로 키우면가 동일한 코드를 모두 구현해야합니다

- (CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath 

을 heightForRowAtIndexPath를 추가하면 tableView1의 셀이 더 이상 동적으로 크기가 지정되지 않습니다. – jacobsieradzki

+0

UITableViewAutomaticDimension은 기본값이며, 콘텐츠 기능의 값 변경을 의미하지는 않습니다. 이 두 가지 방법으로 레이블의 높이를 계산해야합니다 (길이를 사용하고 textSizeForAttributes ..를 사용합니다). 그러나 당신은 제공해야합니다. –