Reputation: 53
How can I configure my tableview below to reflect only the rows with an unhidden cell? Here's the code for the view controller with the tableview in question:
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
}
And this is the function in my TableViewCell for hiding the cell:
func hidePost(post: Post){
self.post = post
if post.username != uid {
self.hidden = true
}
}
Upvotes: 0
Views: 60
Reputation: 384
Make two array and use according to your condition and after any updation reload your table.
Ex:
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
}
Don't Forget to reload your table.
Upvotes: 3
Reputation: 3661
You can use heightForRowAtIndexPath
delegate method and then return 0 for the cells whose corresponding data model hidden is true.
Upvotes: 0