티스토리 뷰

개발

ios Custom Cell Row Height설정

likehood~ 2013. 2. 6. 17:40

Custom Cell 제작시..

heightForRowAtIndexPath에서 높이값을 고정으로 리턴하는 경우가 많다. 사실 커스텀 셀의 높이를 수시로 바꿀일이 없기때문에 size inspecter에서 row height를 보고 박아놔도 상관은 없겠다. 

또는 viewDidLoad에서 tableView.rowHeight에 값을 밖아놔도 되겠다.


하지만 시간이 지나서 셀에 뭔가 를 추가하고 row 높이만 변경해버리면 버그발생되는것이다.

힘들지않다면 아래처럼 하는게 낮지 않을까?

 


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

{

    if(indexPath.section == 0)

    {

        static NSString *CellIdentifierSummary = @"CompletionCell";

        UICompletionViewCell *cellSummary= (UICompletionViewCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifierSummary];

        if(cellSummary == nil)

        {

            NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"UICompletionViewCell" owner:self options:nil];

            cellSummary = (UICompletionViewCell *)[nib objectAtIndex:0];

        }

        return cellSummary.frame.size.height;

    }

    else

    {

        static NSString *CellIdentifier = @"Cell";

        UITableViewCell *cell= (UITableViewCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];

        if(cell == nil)

        {

            cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"Cell" ];

        }

         return cell.frame.size.height;

    }

        

}


'개발' 카테고리의 다른 글

betabuilder를 이용하여 ios Adhoc 배포시 주의사항  (0) 2013.03.07
XCODE 4.6 업데이트 후 메소드 워닝  (0) 2013.02.13
제곱근  (0) 2012.07.16
Hotkey Agent 1.0  (0) 2009.12.28
SimpleMP3  (0) 2009.10.12
댓글