隐藏UITableViewCell中的行

时间:2016-03-15 11:12:21

标签: ios swift uitableview

如何在下面配置我的tableview以仅反映具有隐藏单元格的行?这是视图控制器的代码,其中包含有问题的tableview:

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
    }  
}

2 个答案:

答案 0 :(得分:3)

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

例如:

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 
 } 

不要忘记重新加载你的桌子。

答案 1 :(得分:0)

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

相关问题