sectionHeaderHeight
and estimatedHeaderHeight
should be installed.UITableView.automaticDimension
is what allows AutoLayout to calculate the height of each cell at run time.estimatedHeaderHeight
should be set to roughly estimate the total height of its contents in order to display a scroll indicator.tableView(_: viewForHeaderInSection: )
should return an instance of UIView, but guess what? UITableViewCell is a subclass of UIView. This means that we can use our storyboard to create a cell prototype that can be removed and returned from this function. In my opinion, this is the best way to declare all your views in one place, instead of the many xib files scattered around your project.dequeueReusableCell(withIdentifier identifier: String) -> UITableViewCell?
. We do not use a kind of forIndexPath:
function, because we do not have an indexPath for header lines. In addition, forIndexPath:
states that a reuse identifier is defined for an excluded cell to prevent nil from returning. In our case, the section can be displayed without a title. guard let headerCell = tableView.dequeueReusableCell(withIdentifier: "header") else { return nil }
CGFLOAT_MIN
. It represents the minimum non-negative value for CGFloat. The value is 1.17549435e-38F or 2.2250738585072014e-308 for 32-bit and 64-bit code, respectively. In the end, it is not zero pixels. On the other hand, in a simple table view, the height of the header can be set to any value greater than or equal to 0.tableView(_:estimatedHeightForHeaderInSection:)
and tableView(_:heightForHeaderInSection:)
. As stated in the documentation, two functions must be implemented to determine the height of the custom view.Source: https://habr.com/ru/post/448546/
All Articles