【问题标题】:Hiding rows in the UITableViewCell在 UITableViewCell 中隐藏行
【发布时间】:2016-03-15 11:12:20
【问题描述】:

如何配置下面的表格视图以仅反映具有未隐藏单元格的行?以下是带有相关表格视图的视图控制器的代码:

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {

    let post = posts[indexPath.row]
    if let cell = tableView.dequeueReusableCellWithIdentifier("favorCell") as? FavorCell {
          cell.configureCell(post)
          cell.hidePost(post)
          return cell
    } else {
        return FavorCell()
    }
}

func numberOfSectionsInTableView(tableView: UITableView) -> Int {
    return 1
}

func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return posts.count
}

这是我的 TableViewCell 中用于隐藏单元格的函数:

func hidePost(post: Post){  
    self.post = post
    if post.username != uid {
        self.hidden = true
    }  
}

【问题讨论】:

  • 你需要从 numberOfRowsInSection 管理它
  • 不要隐藏单元格,而是根据您的 posts 数组创建另一个数组,该数组仅包含未隐藏的帖子,并使用该数组来驱动您的表格视图。

标签: ios swift uitableview


【解决方案1】:

根据您的情况制作两个数组并使用,并在任何更新后重新加载您的表格。

例如:

if(is_searching == true) {
      cell.textLabel?.text = Array1[indexPath.row]["xyz"] as! NSString as String
      cell.accessoryView?.hidden = true

 }
 else {
       cell.textLabel?.text = Array2[indexPath.row]["xyz"] as! NSString as String 
 } 

别忘了重新加载表格。

【讨论】:

    【解决方案2】:

    您可以使用heightForRowAtIndexPath委托方法,然后为对应数据模型隐藏为真的单元格返回0。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-05-14
      • 1970-01-01
      相关资源
      最近更新 更多