简体   繁体   中英

How to make tableView Scroll Automatically to top/bottom?

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.

scrollToRowAtIndexPath:atScrollPosition:animated:

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

- (void)scrollToRowAtIndexPath:(NSIndexPath *)indexPath atScrollPosition:(UITableViewScrollPosition)scrollPosition animated:(BOOL)animated

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM