UITableView Detecting Last Cell

前端 未结 8 834
广开言路
广开言路 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条回答
  •  没有蜡笔的小新
    2021-01-31 11:25

    For Xcode 9 and Swift 4/5

    //Show Last Cell (for Table View)
    func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) 
    {
        if indexPath.row == (yourdataArray.count - 1) 
        {
            print("came to last row")
        }
    }
    
    //Show last cell (for Collection View)
    func collectionView(_ collectionView: UICollectionView, willDisplay cell: UICollectionViewCell, forItemAt indexPath: IndexPath) 
    {
        if indexPath.row == (yourdataArray.count - 1)
        {
            // Last cell is visible
        }
    }
    

提交回复
热议问题