ios - UITableView 设置 tableview 行隐藏

标签 ios objective-c uitableview

我在 grouptableview 中有一个自定义的 tableview 单元格。我有一个隐藏的。然后我必须让它可见。单元格标记为 3。

这不适用于我的代码:

if (self.tableView.tag == 3) {
                self.tableView.hidden = NO; //Not working.
            }

我只需要让一行可见。我希望你明白。

最佳答案

SWIFT 中,您需要做两件事,

  1. 隐藏您的手机。 (因为reusable cell可能会冲突)

  2. 将单元格高度设置为

看这里

  1. 隐藏您的手机。

    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let myCell:UITableViewCell = tableView.dequeueReusableCell(withIdentifier: "cellID",for: indexPath) as! UITableViewCell
    
        if(indexPath.row < 2){
            myCell.isHidden = true
        }else{
            myCell.isHidden = false
        }
    
        return myCell
    }
    
  2. 将单元格高度设置为

    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        var rowHeight:CGFloat = 0.0
    
        if(indexPath.row < 2){
            rowHeight = 0.0
        }else{
            rowHeight = 55.0    //or whatever you like
        }
    
        return rowHeight
    } 
    

使用它您可以消除可重复使用的单元格冲突问题。

您可以对 cell?.tag 执行相同的操作,也可以按标签隐藏特定的单元格。

关于ios - UITableView 设置 tableview 行隐藏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16386939/

相关文章:

ios - 隐藏 View 而不留间隙

ios - GPUImageGaussianBlurFilter 似乎不适用于分层过滤器

ios - 如何在 Swift 中从 AWS Mobile Hub 检索电子邮件和电话号码?

ios - 如何在 Objective-C 中将一个 NSMutableArray 存储到另一个 NSMutableArray

iphone - 在另一个循环中循环

objective-c - 将 UIScrollView 上的点击传递给其下方的 Cell

iOS ScrollView 需要约束 y 位置或高度

ios - 向 UITableViewCell 添加分隔符

objective-c - 从 NSArray 为 UITableView 创建索引

objective-c - 这两个实例是同一个类吗? (ReactiveCocoa 文档示例)