美文网首页iOS记录
UITableView回到顶部

UITableView回到顶部

作者: bianruifeng | 来源:发表于2019-12-10 11:16 被阅读0次
//***************方法一***************//
//1.UITableView自带方法滚动到某组某行:
[self.tableView  scrollRectToVisible:CGRectMake(0, 0, 1, 1) animated:NO];
//注意:可能会有数组越界奔溃的情况(如有有section但没有cell的情况),不能保证的情况下不要使用。

//***************方法二***************//
//2.UITableView继承UIScrollView,可以调用UIScrollView滚动到设定区域的的方法
[self.tableView setContentOffset:CGPointMake(0,0) animated:NO];

//***************方法三***************//
//3.设置偏移量
NSIndexPath* indexPat = [NSIndexPath indexPathForRow:0 inSection:0];
[self.tableView scrollToRowAtIndexPath:indexPat atScrollPosition:UITableViewScrollPositionBottom animated:YES];

相关文章

网友评论

    本文标题:UITableView回到顶部

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