asheyla asheyla - 2 months ago 7
iOS Question

Swift determine if you have enough cells to cover the whole screen

Is there an easy way do determine if you have enough

TableViewCells
to cover the whole screen? Like the whole screen space reserved for the
TableView
is covered in
cells
.

I know you can add up the height of each
cell
and the height of group
headers
and the
StatusBar
and any other elements in the screen and see if the sum if less than the height of the screen of the used device. But is there a more elegant and easier way to know?

Answer

You can count it by something like,

  let tableViewLastPoint = self.yourTableView.tableFooterView!.frame.origin.y + self.yourTableView.tableFooterView!.frame.size.height

then compare that if tableViewLastPoint is greater than your screen's height then you have cell that requires more height then screen, else cells are not required full screen!

In this case you should initialize your tableview's footerview with zero frame like,

  self.yourTableView.tableFooterView = UIView.init(frame: CGRectZero)