【发布时间】:2021-07-29 13:55:09
【问题描述】:
我有一个检测最后一个单元格的代码,但我很好奇现在如何检测 tableView 中的第一个单元格,因为在我的 tableView 中,并非所有单元格都在 iphone 7 或更少的设备上可见,这就是我必须这样做的原因使用滚动方法。
func scrollViewDidScroll(_ scrollView: UIScrollView) {
let contentOffsetMaxY: Float = Float(scrollView.contentOffset.y + scrollView.bounds.size.height)
let contentHeight: Float = Float(scrollView.contentSize.height)
let lastCellIsVisible = contentOffsetMaxY > contentHeight
if lastCellIsVisible {
//some action
}
}
【问题讨论】:
-
这能回答你的问题吗? UITableView - scroll to the top
-
@AlexBailey 不,我不需要滚动操作到顶部,我想知道如何使用上面的代码检测所有单元格,至少对于第一个单元格。我只设法检测到最后一个单元格。而像
willDisplayCell这样的方法不起作用
标签: swift uitableview uiscrollview