Hide UITableView by setting row height to 0?

I just inherited code that hides / shows UITableView rows using the delegate method heightForRowAtIndexPath and returns a height of 0 for "hidden rows".

The code works, but it bothers me, which can be fraught with unforeseen complications. Can someone alleviate my problems or give me good reasons why this might cause problems (I could not find any problems with the initial testing).

The table is quite small at 10 rows and will require a custom row height even without this hidden row solution.

+4
source share
3 answers

It would be easier to add and remove lines between two calls to beginUpdates and endUpdates , but I don't understand why this 0-height method should not work.

If there are no UI artifacts, that is (for example, the Delete button, which displays the overflow in the next cell).

0
source

I am doing the same thing in the code that I just worked on. I am not happy with the different behavior for the different table view settings.
The alternative in my case is more complex (a model that adapts to what is visible or not).
At the moment, I am posting a // HACK comment and documenting a few features.
This is what I found (iOS 5.0):

  • Set tableView.rowHeight = 1; Zero will give a cell with zero height (as tableView returns: tableView heightForRowAtIndexPath :) some default height.
  • You must have a cell separator. If none is selected, the default height is assigned to rows with zero height. Height 1 is included in the divider.

If your code works differently, it would be interesting to know how it is configured.

0
source

I use this method to determine the hidden cell heights of 0. It works well, and also means that I can animate the inclusion of new cells by expanding the height of the cell (for example, adding a DatePicker Cell as a calendar application).

A few things that I had to observe in iOS 7.1 are that very compressed text still appears even when the cell height is 0, so I needed to remove the cell text in this case. In addition, I resized the separatorInset cell, which also appeared.

0
source

Source: https://habr.com/ru/post/1383668/


All Articles