Вот, пожалуйста.Этот также удаляет вертикальное пространство.
NSInteger sectionToRemove = 1;
CGFloat distance = 10.0f; // minimum is 2 since 1 is minimum for header/footer
BOOL removeCondition; // set in viewDidLoad
/**
* You cannot remove sections.
* However, you can set the number of rows in a section to 0,
* this is the closest you can get.
*/
- (NSInteger)tableView:(UITableView *)tableView
numberOfRowsInSection:(NSInteger)section {
if (removeCondition && section == sectionToRemove)
return 0;
else
return [super tableView:self.tableView numberOfRowsInSection:section];
}
/**
* In this case the headers and footers sum up to a longer
* vertical distance. We do not want that.
* Use this workaround to prevent this:
*/
- (CGFloat)tableView:(UITableView *)tableView
heightForFooterInSection:(NSInteger)section {
return removeCondition &&
(section == sectionToRemove - 1 || section == sectionToRemove)
? distance / 2
: distance;
}
- (CGFloat)tableView:(UITableView *)tableView
heightForHeaderInSection:(NSInteger)section {
return removeCondition &&
(section == sectionToRemove || section == sectionToRemove + 1)
? distance / 2
: distance;
}