ios tableview 滚动到最后的cell 崩溃

2019-12-17  本文已影响0人  jasperWhf

ios中很多场景下,需要自动滚动到页面最后的cell,通常调用此方法,太坑了,当tableview 数据源量大的时候,会出现数据没刷新完,就滚动到最后一行,数据源是 100  index 也是100,数组越界崩溃。

[self.tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:indexOfLastRow inSection:0] atScrollPosition:UITableViewScrollPositionBottom animated:NO]

建议做法:

CGPoint offset = CGPointMake(0,self.tableView.contentSize.height -self.tableView.frame.size.height);

  [self.tableView setContentOffset:offset animated:NO];

看代码,完美解决问题。

上一篇 下一篇

猜你喜欢

热点阅读