iOS Quick Tip – programmatically hiding sections of a UITableView with static cells
-(UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { if(hideTableSection && section == 1) return [[UIView alloc] initWithFrame:CGRectZero]; return nil; } - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section { if(section == 1 && hideTableSection) return 1; return 32; }
注意:返回高度为1,而不是0
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section { if(section == 1 && hideTableSection) return 1; return 16; } -(UIView*)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section { if(section == 1 && hideTableSection) return [[UIView alloc] initWithFrame:CGRectZero]; return nil; }
http://code-ninja.org/blog/2012/02/29/ios-quick-tip-programmatically-hiding-sections-of-a-uitableview-with-static-cells/
签名:删除冗余的代码最开心,找不到删除的代码最痛苦!