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
};