UITableView Detecting Last Cell

前端 未结 8 747
广开言路
广开言路 2021-01-31 10:46

How can I detect when a UITableView has been scrolled to the bottom so that the last cell is visible?

8条回答
  •  闹比i
    闹比i (楼主)
    2021-01-31 11:48

    I found this solution:

    func scrollViewDidScroll(_ scrollView: UIScrollView) {
          let contentOffsetMaxY: Float = Float(scrollView.contentOffset.y + scrollView.bounds.size.height)
          let contentHeight: Float = Float(scrollView.contentSize.height)
          let lastCellIsVisible = contentOffsetMaxY > contentHeight + somePaddingIfWanted
          if lastCellIsVisible {
               doSomething()
          }
    }
    

提交回复
热议问题