iOS控件之UITableView之滚动

滚动有三种方式:

1.  [self.tableView scrollRectToVisible:CGRectMake(0, 0, 1, 1) animated:YES];

2. [self.tableView setContentOffset:CGPointMake(0,0) animated:YES];

3. NSIndexPath* indexPath = [NSIndexPath indexPathForRow:0 inSection:0];

[self.tableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionBottom animated:YES];

 

其中,方式2 是最不好控制的,要按照offset来设置

方式3 要设置indexPath,有时会导致越界

对于滚动到顶部来说,当然是 方式1 更好

 

但是,很显然,方式3 提供更多选择,atScrollPosition选项,让显示的indexPath的位置更加地灵活

posted on 2018-05-15 16:56  大木哥  阅读(272)  评论(0编辑  收藏  举报

导航