Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to hide specific cells in a static UItableview, in swift?

No article explains it clearly regarding my query, I have three cells in a static table and I want to hide second cell when users taps on first cell. Any kind of help is appreciated.

like image 679
coolly Avatar asked May 29 '16 21:05

coolly


People also ask

How do I deselect a selected UITableView cell?

How to deselect a UITableViewCell using clearsSelectionOnViewWillAppear. If you set this property to be true the user's selected cell will automatically be deselected when they return to the table view.

How can we use a reusable cell in UITableView?

For performance reasons, a table view's data source should generally reuse UITableViewCell objects when it assigns cells to rows in its tableView(_:cellForRowAt:) method. A table view maintains a queue or list of UITableViewCell objects that the data source has marked for reuse.


1 Answers

Although you cannot stop the static table from trying to show your cells, you can set their height to zero, making them effectively invisible:

Add this method to your table view controller delegate class:

func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
    let cell = super.tableView(tableView, cellForRowAtIndexPath: indexPath)
    return cell == myHiddenCell ? 0 :  super.tableView(tableView, heightForRowAtIndexPath:indexPath)
}
like image 112
Sergey Kalinichenko Avatar answered Sep 20 '22 06:09

Sergey Kalinichenko