Swift 确定您是否有足够的单元格来覆盖整个屏幕

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

有没有一种简单的方法可以确定您的 TableViewCells 是否足以覆盖整个屏幕?就像为 TableView 保留的整个屏幕 space 被 cells 覆盖。

我知道您可以将每个 cell 的高度与组 headersStatusBar 以及屏幕中任何其他元素的高度相加,看看总和是否小于所用设备屏幕的高度。但是有没有更优雅更容易知道的方法呢?

你可以这样算,

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

然后比较一下,如果 tableViewLastPoint 大于屏幕的高度,那么您的单元格需要比屏幕更高的高度,否则单元格不需要全屏!

在这种情况下,您应该初始化您的 tableview's footerview with zero frame,例如,

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