UITableView Detecting Last Cell

前端 未结 8 745
广开言路
广开言路 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:26

    For Xcode 8 and swift 3

    func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
            let lastSectionIndex = tableView.numberOfSections - 1
            let lastRowIndex = tableView.numberOfRows(inSection: lastSectionIndex) - 1
            if indexPath.section ==  lastSectionIndex && indexPath.row == lastRowIndex {
                print("this is the last cell")
            }
        }
    

提交回复
热议问题