uitableview - 隐藏静态TableView的部分

标签 uitableview hide tableview

我发现本教程隐藏了静态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/

相关文章:

ios - 使用 Interface Builder 将 UITableView 放在导航栏下方

ios - UITableViewCell 没有正确更新 swift 2.2

jquery - 隐藏嵌套在两个 div 内的 <li>

java - 如何防止在 JavaFX 的 TableView 中选择另一行

qml - 无法在QML中选择TableView的行

swift - 错误 : "Unexpected nil index path in _canPerformAction:forCell:sender:, this should never happen."

ios - 如何使 UITableViewCell 的高度更长?

javascript - jQuery .hide() 在某些浏览器中不起作用

javascript - Bootstrap 模式隐藏方法 - 无事件静默?

ios - Tableview button.tag 抛出 lldb