0
如何配置我的tableview以僅反映具有非隱藏單元格的行?這是一個有問題的實現代碼如下視圖控制器代碼:在UITableViewCell中隱藏行
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'數組創建另一個數組,並使用該數組來驅動您的tableview。 – Paulw11