본문 바로가기

프로그램 경험/iOS

[iPhone] UITableViewCell에 높이 조절하기

테이블 셀의 높이가 각각 다른 테이블을 만드는중 문제가 생겼다.
테이블 셀의 뷰를 놓고 그 위에 텍스트 박스를 놓았는데 텍스트 내용의 길이에 따라서 높낮이를 조절해야 한다.

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
if ([indexPath row] == 0) {
return 100;
}
    return 80;
}

- (UITableViewCell *)tableView:(UITableView *)tableView 
         cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{
    
static NSString *cellId = @"cellId ";
CellId *cell = (CellId *)[tableView 
dequeueReusableCellWithIdentifier: cellId];
if (cell == nil)  
{
cell = [[[NSBundle mainBundle] loadNibNamed:@"CellId" 
 owner:self options:nil] lastObject];
}
if ([indexPath row] == 0) {
    
//CGRect rect = cell.view.bounds; 이걸로는 안되더라..
//cell.view.bounds = CGRectMake(rect.origin.x,rect.origin.y, 768, 100); //.size = CGSizeMake(768, 100);
CGRect rect = cell.view.frame;
cell.view.frame = CGRectMake(rect.origin.x,rect.origin.y, 768, 100);
}
    
return cell;
}