美文网首页
iOS tableView滚动到相应位置

iOS tableView滚动到相应位置

作者: 清风_____ | 来源:发表于2022-01-17 14:30 被阅读0次

1、tableView一行代码滚动到顶部

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

tableView一行代码滚动对应cell

//获取到需要跳转位置的行数
NSIndexPath *scrollIndexPath = [NSIndexPath indexPathForRow:10 inSection:0];
//滚动到其相应的位置
[[self tableView] scrollToRowAtIndexPath:scrollIndexPath
        atScrollPosition:UITableViewScrollPositionTop animated:YES];

枚举类型

以下枚举决定滚动到指定位置的哪个位置
typedef NS_ENUM(NSInteger, UITableViewScrollPosition) {
    UITableViewScrollPositionNone,
    UITableViewScrollPositionTop,    
    UITableViewScrollPositionMiddle,   
    UITableViewScrollPositionBottom
};

2、scrollView一行代码滚动到顶部

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

https://www.jianshu.com/p/8f6b8b2be986
https://www.cnblogs.com/hero11223/p/9237205.html

相关文章

网友评论

      本文标题:iOS tableView滚动到相应位置

      本文链接:https://www.haomeiwen.com/subject/qruchrtx.html