2012-09-20 4 views
-1

가능한 중복 :
Setting custom UITableViewCells height동적 크기

내가 들어있는 TableView를 사용자 정의 cells.I 테이블 cells.But에 표시 할 텍스트를 포함하는 객체가 텍스트의 크기가 다를 수 있으므로 콘텐츠 크기에 따라 셀 크기를 늘리거나 줄여야합니다. 어떻게해야합니까?

+0

많은 링크가 있습니다. 예를 들어 [this] (http://www.cimgf.com/2009/09/23/uitableviewcell-dynamic-height/)와 같이. 그건 그렇고, 당신은 더 많은 답변을 받아 들일 필요가 있습니다. 귀하의 비율은 0 %입니다. – FluffulousChimp

+0

이 질문에 사용할 수있는 토론이 너무 많습니다. – cancerian

답변

1

먼저 text에 따라 cell 필요한 크기를 계산하십시오.

CGSize boundingSize = CGSizeMake(220.0, 500); 
//Adjust your Font name and size according to you 
CGSize requiredSize = [cell.txtViewDescription.text sizeWithFont:[UIFont fontWithName:@"Helvetica" size:13.0] constrainedToSize:boundingSize lineBreakMode:UILineBreakModeWordWrap]; 
CGFloat requiredHeight = requiredSize.height; 
requiredHeight = requiredHeight + 20.0; 

지금이 그냥 생각입니다 cell Height

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

할당하려면이 방법을 사용합니다. 모든 것은 논리에 달려 있습니다. 행운을 빕니다!