Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hide a UITableView by setting row height to 0?

I just inherited code which hides/shows rows a UITableView by using the delegate heightForRowAtIndexPath method and returning height 0 for "hidden rows".

The code works, but it has me concerned there might be fraught with unforeseen complications. Can someone either ease my concerns or give me good reasons why this could cause problems (I couldn't find any issues with initial testing).

The table is fairly small <10 rows total and would require custom row heights even without this hidden row solution.

like image 431
DBD Avatar asked Oct 10 '22 08:10

DBD


1 Answers

I do the same thing in the code I just worked on. I am not happy with different behaviour for different table view settings.
The alternative in my case is more complex (a model that adapts to what is visible or not).
For now, I put a //HACK comment on it and document a few peculiarities.
This is what I have found (iOS 5.0 tested):

  1. Set tableView.rowHeight = 1; Zero will give a cell with zero height (as returned by tableView:tableView heightForRowAtIndexPath:) some default height.
  2. You must have a cell separator. If none is selected, then a default height is assigned to zero height rows. The height of 1 is included with the separator.

If your code works in a different way, it would be interesting to know how it is set up.

like image 125
emp Avatar answered Oct 13 '22 11:10

emp