当第一部分滚动到视野之外时,我正在尝试删除它。
我使用下面的委托(delegate)方法进行了尝试,但由于我没有页脚 View ,所以没有帮助。
func tableView(_ tableView: UITableView, didEndDisplayingFooterView view: UIView, forSection section: Int)
另外,我尝试使用 ScrollView 委托(delegate)
func scrollViewDidEndDragging(_ scrollView: UIScrollView, willDecelerate decelerate: Bool){
let indexPath = tableView.indexPathsForVisibleRows?.first
if indexPath?.section == 1 {
//remove View
}
}
你能告诉我如何检测第一部分何时消失吗?
最佳答案
您可以使用 ...didEndDisplayingCell...
委托(delegate)中的功能:
func tableView(_ tableView: UITableView, didEndDisplaying cell: UITableViewCell, forRowAt indexPath: IndexPath) {
if indexPath.section == 0 && indexPath.row == lastRowInFirstSection {
// first section is out
}
}
请注意,一旦每个单元格从屏幕顶部或底部移出,就会调用此函数,因此您需要检查
indexPath
确保这是您需要的单元格。如果需要,您还可以检查第二部分是否可见,以检测第一部分是否从底部流出:
func tableView(_ tableView: UITableView, didEndDisplaying cell: UITableViewCell, forRowAt indexPath: IndexPath) {
if indexPath.section == 0 && indexPath.row == lastRowInFirstSection {
if tableView.indexPathsForVisibleRows?.contains (where: { $0.section == 0 }) == true {
// It goes out from bottom. So we have to check for the first cell if needed
} else {
// It goes out from top. So entire section is out.
}
}
}
关于ios - 检测 UITableView 部分何时滚动出 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59011367/