您的位置:首页 > 产品设计 > UI/UE

UITableView 滚动到指定行cell

2015-11-15 00:33 423 查看
1.滚动到指定的cell

设置需要滚动到的cell的NSIndexPath[NSIndexPath indexPathForRow: inSection:]
滚动到指定cell

[self.tableview selectRowAtIndexPath:[NSIndexPath indexPathForRow:arc4random_uniform(29) inSection:0] animated:YES scrollPosition:UITableViewScrollPositionTop];

2.与1类似的方法

[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
};
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  uitableview cell 滚动