我发现本教程隐藏了静态TableView的一部分:http://code-ninja.org/blog/2012/02/29/ios-quick-tip-programmatically-hiding-sections-of-a-uitableview-with-static-cells/
它很好用,但只有在不修改的情况下,如果我添加一个节或一行,它就不好用。我是初学者,无法修改它,有人可以帮我隐藏多个部分吗?
非常感谢!
最佳答案
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
if (section == 2 && _hideTableSection) {
//header height for selected section
return 0.1;
} else {
//keeps all other Headers unaltered
return [super tableView:tableView heightForHeaderInSection:section];
}
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
if (section == 2 && _hideTableSection) {
//header height for selected section
return 0.1;
} else {
// keeps all other footers unaltered
return [super tableView:tableView heightForFooterInSection:section];
}
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
if (section == 1) { //Index number of interested section
if (hideTableSection) {
return 0; //number of row in section when you click on hide
} else {
return 2; //number of row in section when you click on show (if it's higher than rows in Storyboard, app will crash)
}
} else {
return [super tableView:tableView numberOfRowsInSection:section]; //keeps inalterate all other rows
}
}
关于uitableview - 隐藏静态TableView的部分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17761878/