How to determine if the user has scrolled to the bottom of the UITableView?

后端 未结 3 1166
夕颜
夕颜 2021-02-14 03:36

How can I determine if the user has scrolled to the last cell/bottom of a UITableView?

3条回答
  •  有刺的猬
    2021-02-14 03:57

    UITableView inherits from UIScrollView, and scroll view exposes a contentOffset property (documentation here).

    Use this with a bit of math to determine if the contentOffset is within frame.size.height of the bottom.

    Update: here's a stab at a formula that will give you what you want:

    if(tableView.contentOffset.y >= (tableView.contentSize.height - tableView.frame.size.height)) {
      //user has scrolled to the bottom
    }
    

提交回复
热议问题