How to make tableView Scroll Automatically to top/bottom?

后端 未结 2 852
小鲜肉
小鲜肉 2021-01-03 19:01

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 scr

相关标签:
2条回答
  • 2021-01-03 19:21

    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.

    0 讨论(0)
  • 2021-01-03 19:40

    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
    
    0 讨论(0)
提交回复
热议问题