프로그래밍/iOS, macOS, Objective-C
[Xcode/iOS] UITableView의 Cell 높이 설정하기.
고독한 프로그래머
2011. 8. 29. 16:25
1번째 방법..
UITableViewController 클래스를 상속받은 클래스.m 파일에서 다음과 같이 처리해주면 됩니다.
- (void)viewDidLoad
{
[super viewDidLoad];
self.tableView.rowHeight = 60;
}
|
반드시 viewDidLoad에서 해줘야 하는건 아닙니다만 보통 테이블 로드될 때 처리해주는게 맞겠죠.
2번째 방법.. 각 셀마다 다른 높이를 주고 싶은 경우, tableView:heightForRowAtIndexPath: 메소드를 구현한 후, indexPath에 해당하는 높이를 리턴해주면 됩니다.
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
int height = self.tableView.rowHeight;
int row = [indexPath row];
switch (row) {
case 0:
height = 50;
break;
case 1:
height = 100;
break;
default:
break;
}
return height;
}
|
※ 퍼가실땐 출처를 밝혀주세요. (http://shkam.tistory.com/)