如何检测具有很多部分的 tableview 的底部?(迅速)

0 detect tableview ios sections swift

我想知道如何检测何时在 swift4 中有很多部分的 tableView 单元格底部向下滚动。

我知道我可以使用此功能检测到它,

func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {} 
Run Code Online (Sandbox Code Playgroud)

但它仅在有 1 个部分时才有效。

当有很多部分时,请让我知道如何检测 tableview 单元格的底部。

小智 5

您可以通过使用UIScrollViewDelegate和检查contentOffset

extension YourViewController: UIScrollViewDelegate {

    func scrollViewDidScroll(_ scrollView: UIScrollView) {
        if scrollView.contentSize.height - scrollView.contentOffset.y - scrollView.frame.height < 100 {
            // only 100 pt are left from the bottom
        }
    }

}
Run Code Online (Sandbox Code Playgroud)