There are some section in the table that does not contain any data and would like to hide that section.
How to do this?
For hiding a section, even in the middle of the table view you would need all of the following
#define DEBUG_SECTION 1
#if ! DEBUG_BUILD
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
if (section == DEBUG_SECTION)
return CGFLOAT_MIN;
return [super tableView:tableView heightForHeaderInSection:section];
}
//------------------------------------------------------------------------------
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
if (section == DEBUG_SECTION)
return CGFLOAT_MIN;
return [super tableView:tableView heightForFooterInSection:section];
}
//------------------------------------------------------------------------------
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
if (section == DEBUG_SECTION)
return nil;
return [super tableView:tableView titleForHeaderInSection:section];
}
//------------------------------------------------------------------------------
- (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section
{
if (section == DEBUG_SECTION)
return nil;
return [super tableView:tableView titleForFooterInSection:section];
}
//------------------------------------------------------------------------------
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if (section == DEBUG_SECTION)
return 0;
return [super tableView:tableView numberOfRowsInSection:section];
}
//------------------------------------------------------------------------------
#endif // #if ! DEBUG_BUILD
if you left out titleFor/headerFor... you will get some empty rows
if you left out heightFor... the title/footer header text will still appear