在做口语录音的时候,需要录完一句,自动跳转下一句,并将下一句至于屏幕顶部。此过程中发现tableview总是滚动,原因就是reloadRowsAtIndexPaths导致的。
- 原因是:因为一些神秘的原因,tableview刷新的时候,会使用到预估的行高,如果你没有设置预估的行高的话,会出现上下滑动的效果,你可以缓存你的行高,在estimatedHeightForRowAtIndexPath中返回缓存的行高。
- 解决有两种方式:
方式一:
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
return 85;
}
- (CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath {
return 85;
}
方式二:
_tableView.estimatedRowHeight = 85;
_tableView.rowHeight = 85;
网友评论