如何使tableView自动滚动到顶部/底部? [英] How to make tableView Scroll Automatically to top/bottom?

查看:154
本文介绍了如何使tableView自动滚动到顶部/底部?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这只是一个测试,我可以将它添加到应用程序。嗯....我有一个 tableView


  1. 如果点击 button1 ,我想让tableView自动向上滚动到顶部。


  2. 如果我点击 button2 ,我想让tableView自动向下滚动到底部。


如何做到这一点?你还可以看看滚动视图的 setContentOffset:animated:

code>方法。



转到页首意味着

  [self.tableView setContentOffset:CGPointZero animated:YES]; 

,底部是

  CGFloat height = self.tableView.contentSize.height  -  self.tableView.bounds.size.height; 
[self.tableView setContentOffset:CGPointMake(0,height)animated:YES];

您将无法控制动画持续时间。



scrollToRowAtIndexPath:atScrollPosition:animated:的唯一问题是当设置节和表标题时可能不会有帮助。


This is just a test, which i might add it to the app. Well.... I have a tableView.

  1. If click button1, I want the tableView to scroll up automatically to the top.

  2. If I click button2 I want the tableView to scroll down automatically to the bottom.

How can this be done ? What about Scroll Speed ?

解决方案

You can also look at the scroll view's setContentOffset:animated: method.

Going to the top would mean,

[self.tableView setContentOffset:CGPointZero animated:YES];

and the bottom would be,

CGFloat height = self.tableView.contentSize.height - self.tableView.bounds.size.height;
[self.tableView setContentOffset:CGPointMake(0, height) animated:YES];

You won't have control over the animation duration.

The only problem with scrollToRowAtIndexPath:atScrollPosition:animated: is that it might not be helpful when section and table headers are set.

这篇关于如何使tableView自动滚动到顶部/底部?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆