gpt4 book ai didi

iphone - TTTableViewController scrollsToTop 不工作

转载 作者:可可西里 更新时间:2023-11-01 17:12:09 24 4
gpt4 key购买 nike

我正在使用基本的 Three20 TTTableViewController 子类,它使用自己的数据源和模型。

问题是我似乎无法使用表的 scrollsToTop 属性。这是表格的标准属性,继承自 UIScrollView,非常常用。

我在类里面的许多不同位置/方法中尝试了以下所有方法:

self.tableView.scrollsToTop = YES;
[self.tableView setScrollsToTop:YES]


我也尝试过重写该方法

- (BOOL)scrollViewShouldScrollToTop:(UIScrollView *)scrollView {
return YES;
}

都没有成功。

注意。为了清楚起见,我指的是点击状态栏以将可见表格 View 滚动到顶部(即第一行)的标准手势。

非常感谢任何帮助!

最佳答案

有些困惑

根据 Apple documentation of UIScrollView :

scrollsToTop

A Boolean value that controls whether the scroll-to-top gesture is effective

这只是告诉 scrollview 点击状态栏会使 View 滚动到顶部。

您要找的是this UITableView method :

scrollToRowAtIndexPath:atScrollPosition:animated:

Scrolls the receiver until a row identified by index path is at a particular location on the screen.

使用three20

由于您使用的是 three20,因此可以轻松完成您想要做的事情,这要归功于它的 UITableView+Additions.h > - (void)scrollToFirstRow:( BOOL)动画

[self.tableView scrollToFirstRow:YES];

没有three20

如果不使用 three20,下面是 three20 的作用:

- (void)scrollToFirstRow:(BOOL)animated {
if ([self numberOfSections] > 0 && [self numberOfRowsInSection:0] > 0) {
NSIndexPath* indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
[self scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionTop
animated:NO];
}
}

另一种方法

我认为这也可行(未经测试),直接使用 UIScrollView,(也从 three20 中提取):

- (void)scrollToTop:(BOOL)animated {
[self setContentOffset:CGPointMake(0,0) animated:animated];
}

或:

[self.tableView setContentOffset:CGPointMake(0,0) animated:YES];

关于iphone - TTTableViewController scrollsToTop 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3759920/

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