How to make tableView Scroll Automatically to top/bottom?

后端 未结 2 853
小鲜肉
小鲜肉 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.

提交回复
热议问题