1.滚动到指定的cell
设置需要滚动到的cell的NSIndexPath
[NSIndexPath indexPathForRow: inSection:]
滚动到指定cell
[self.tableview selectRowAtIndexPath:[NSIndexPath indexPathForRow:arc4random_uniform(29) inSection:0] animated:YES scrollPosition:UITableViewScrollPositionTop];
[self.tableview scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:temp inSection:0] atScrollPosition:UITableViewScrollPositionBottom animated:YES];
3.滚动到最近选中的cell(选中的cell消失在屏幕中,触发事件可以滚动到选中的cell)
[self.tableview scrollToNearestSelectedRowAtScrollPosition:UITableViewScrollPositionTop animated:YES];
1,2,3用到的枚举
typedef NS_ENUM(NSInteger, UITableViewScrollPosition) {
UITableViewScrollPositionNone,
UITableViewScrollPositionTop,
UITableViewScrollPositionMiddle,
UITableViewScrollPositionBottom
};