How can I detect when a UITableView
has been scrolled to the bottom so that the last cell is visible?
33834 次
8 に答える
41
内部tableView:cellForRowAtIndexPath:
またはtableView:willDisplayCell:forRowAtIndexPath:
このように:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
...
NSInteger sectionsAmount = [tableView numberOfSections];
NSInteger rowsAmount = [tableView numberOfRowsInSection:[indexPath section]];
if ([indexPath section] == sectionsAmount - 1 && [indexPath row] == rowsAmount - 1) {
// This is the last cell in the table
}
...
}
于 2010-07-13T20:55:54.063 に答える
26
メソッドを UITableViewDelegate に実装しtableView:willDisplayCell:forRowAtIndexPath:
、最後の行かどうかを確認します。
于 2010-07-13T20:52:35.610 に答える
1
私はこの解決策を見つけました:
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 + somePaddingIfWanted
if lastCellIsVisible {
doSomething()
}
}
于 2020-11-06T11:33:04.083 に答える