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

后端 未结 3 1197
夕颜
夕颜 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 04:05

    Thanks to newer iOS versions, there's an easy way with the willDisplayCell function:

    func tableView(tableView:UITableView, willDisplayCell cell:UITableViewCell, forRowAtIndexPath indexPath:NSIndexPath) {
    
           if (indexPath.row >= tableView.numberOfRowsInSection(0)) {
    
               NSLog("User got to bottom of table")
    
           } 
    }
    

    Note that UICollectionViews have a similar function:

    func collectionView(collectionView: UICollectionView, willDisplayCell cell: UICollectionViewCell, forItemAtIndexPath indexPath: NSIndexPath) {
    
    }
    

提交回复
热议问题