There are some section in the table that does not contain any data and would like to hide that section.
How to do this?
You can set the particular section rows height to 0. Also, with the section header if you want. Datasource would still be there, only not showing up.
Section Rows
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.section == 0) {
if (_shouldHidden) {
return 0.0;
}
else {
return 55.0;
}
}
else {
return 55.0;
}
}
I disagree with Tim. We have a way to access any section/row of a table from anywhere in our code and change its .hidden property (and all other properties).
This is the way I usually use:
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:2];
[self.SeymourCakesTableView cellForRowAtIndexPath:indexPath].hidden = YES;
It is true that 0 is not a valid height for headers and footers. However, the heights are CGFloat values. You can specify a very small number (I've used 0.1) for the height of the section headers and footers.
Kind of a hack, but it works.
You can't "hide" a section as such, but you can "delete" it from the table view using the deleteSections:withRowAnimation:
method. This will remove it from the view, with an optional animation, without affecting your backing data. (You should, however, update the data anyway so that the section doesn't reappear.)
More info: UITableView class reference
You probably need to remove the section itself from the data backing your table. I don't think there's anything that lets you just hide a section.
You can set the number of rows in that section to 0. However, it will leave a noticeable blank area where it used to be.