gpt4 book ai didi

ios - 如何知道 UITableView 何时在 iPhone 中滚动到底部?

转载 作者:IT王子 更新时间:2023-10-29 07:29:27 25 4
gpt4 key购买 nike

我想知道 UITableView 何时滚动到底部以加载和显示更多内容,例如委托(delegate)或其他东西让 Controller 知道表格何时滚动到底部.

我该怎么做?

最佳答案

在 tableview 委托(delegate)中做这样的事情

ObjC:

- (void)scrollViewDidScroll:(UIScrollView *)aScrollView {
CGPoint offset = aScrollView.contentOffset;
CGRect bounds = aScrollView.bounds;
CGSize size = aScrollView.contentSize;
UIEdgeInsets inset = aScrollView.contentInset;
float y = offset.y + bounds.size.height - inset.bottom;
float h = size.height;
// NSLog(@"offset: %f", offset.y);
// NSLog(@"content.height: %f", size.height);
// NSLog(@"bounds.height: %f", bounds.size.height);
// NSLog(@"inset.top: %f", inset.top);
// NSLog(@"inset.bottom: %f", inset.bottom);
// NSLog(@"pos: %f of %f", y, h);

float reload_distance = 10;
if(y > h + reload_distance) {
NSLog(@"load more rows");
}
}

swift :

func scrollViewDidScroll(_ scrollView: UIScrollView) {
let offset = scrollView.contentOffset
let bounds = scrollView.bounds
let size = scrollView.contentSize
let inset = scrollView.contentInset
let y = offset.y + bounds.size.height - inset.bottom
let h = size.height
let reload_distance:CGFloat = 10.0
if y > (h + reload_distance) {
print("load more rows")
}
}

关于ios - 如何知道 UITableView 何时在 iPhone 中滚动到底部?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5137943/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com