IOS:UITableView
An instance of UITableView (or simply, a table view) is a means for displaying and editing hierarchical lists of information.
Count UITableView Row
UITableView의 Row개수를 획득할 수 있는 방법은 아래와 같다.
- (int) countTableViewRow
{
int sections = [_tableView numberOfSections];
int rows = 0;
for (NSInteger sectionCount = 0; sectionCount < sections; sectionCount++) {
rows += [_tableView numberOfRowsInSection:sectionCount];
}
return rows;
}
How to add custom cell
UITableView에 사용자 정의 UITableViewCell(with XIB)을 찾아내는 방법은 아래와 같다.
CustomTableCell *cell = (CustomTableCell*)[tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if(cell == nil)
{
NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"CustomTableCell" owner:self options:nil];
for (id currentObject in topLevelObjects){
if ([currentObject isKindOfClass:[UITableViewCell class]]){
cell = (CustomTableCell*) currentObject;
break;
}
}
}
Troubleshooting
UITableView와 관련된 문제점 해결방법 정리.
cellForRowAtIndexPath not called on reload
UITableview의 reload를 호출해도 UITableViewDataSource의 cellForRowAtIndexPath가 정상적으로 호출되지 않을 경우의 문제점을 해결하는 방법이다.
Initialize check
아래와 같은 방식으로 UITableView를 초기화 했는지 확인해 보자. You have no xib then where you are declared/sets your tableview's properties. Like
self.tableView.frame = CGRectMake(0, 45, 320, 500);
self.tableView.rowHeight = 34.0f;
self.tableView.separatorStyle=UITableViewCellSeparatorStyleNone;
[self.view addSubview:self.tableView];
[self.tableView setBackgroundColor:[UIColor clearColor]];
self.tableView.showsVerticalScrollIndicator=NO;
self.tableView.dataSource = self;
self.tableView.delegate = self;
Try with
Use Main Thread
만약 Main Thread에서 호출하지 않을 경우 아래와 같이 시도해 볼 수 있다.
메인스레드인지 확인하기 위하여 [NSThread isMainThread]를 사용할 수 있다.
heightForRowAtIndexPath: return 0?
Cell의 높이가 0이 아닌지 확인해 볼 수 있다.
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
// ...
return 0.0f; // error!
}
만약 0을 반환할 경우 cellForRowAtIndexPath가 호출되지 않는다.
See also
Favorite site
- Developer apple: UITableView Class Reference
- IOS UITableView Custom Cell
- UITableView의 Cell 높이 설정하기
- iPhone 3.0에서는 UITableViewCell의 높이 지정을 rowHeight를 사용하자
- UITableView에서 header와 footer 높이 변경하기
- UITableViewCell문자의 줄수에 따라서 셀의 높이 조정
UITableView Tutorial
- UITableView끝장보기 (1) 델리게이트 구현이론 1
- UITableView끝장보기 (2) 그룹과 셀 2
- UITableView끝장보기 (3) 셀의 구조 3
- UITableView끝장보기 (4) 테이블 편집 4
- UITableView끝장보기 (5) 인덱스 5
- UITableView끝장보기 (6) 커스텀 셀 6