I have a grouped UITableView where not all sections may be displayed at once, the table is driven by some data that not every record may have. My trouble is that the record
Here is the most elegant solution I've found based on all the answers here, plus this answer:
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
if ([tableView.dataSource tableView:tableView numberOfRowsInSection:section] == 0) {
return nil;
} else {
// Return title normally
}
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
if ([self tableView: tableView numberOfRowsInSection: section] == 0) {
return 0.01f;;
}
return UITableViewAutomaticDimension;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
if ([self tableView: tableView numberOfRowsInSection: section] == 0) {
return 0.01f;;
}
return UITableViewAutomaticDimension;
}