加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ios – 告诉UITableView是否滚动到顶部

发布时间:2020-12-15 01:40:09 所属栏目:百科 来源:网络整理
导读:我试过这个: - (void)scrollViewDidScrollToTop:(UIScrollView *)scrollView 但是当我将表视图滚动到顶部时,它没有触发. - (void)scrollViewDidScroll:(UIScrollView *)scrollView 发火,所以代表不是问题. 在viewDidLoad我也设置了[myTbl setDoesScrollToTo
我试过这个:

- (void)scrollViewDidScrollToTop:(UIScrollView *)scrollView

但是当我将表视图滚动到顶部时,它没有触发.

- (void)scrollViewDidScroll:(UIScrollView *)scrollView

发火,所以代表不是问题.

在viewDidLoad我也设置了[myTbl setDoesScrollToTop:YES];

解决方法

当用户单击状态栏并将scrollsToTop属性设置为YES时,scrollViewDidScrollToTop:方法将触发.从文档:

The scroll view sends this message when it finishes scrolling to the top of the content. It might call it immediately if the top of the content is already shown. For the scroll-to-top gesture (a tap on the status bar) to be effective,the scrollsToTop property of the UIScrollView must be set to YES.

如果用户手动滚动到顶部,则不会触发.如果要处理这种情况,您将必须实现scrollViewDidScroll:方法,并检查滚动条是否位于顶部.

您可以通过contentOffset财产进行检查,例如:

if (scrollView.contentOffset.y == 0) { // TOP }

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读