这是通常情况下我们用来解决tableView乱跳的方法,但是这次我使用了estimatedHeight和约束来自适应高度,这种方法就不能用了
UITableView.appearance.estimatedRowHeight = 0;
UITableView.appearance.estimatedSectionFooterHeight = 0;
UITableView.appearance.estimatedSectionHeaderHeight = 0;
于是我异想天开写出了这个方法,然后发现不怎么好用。。。
//暴力阻止由于使用了estimatedHeight导致的乱跳
CGPoint offset = tableView.contentOffset;
CGRect frame = tableView.frame;
tableView.frame = CGRectMake(tableView.x, -offset.y, tableView.width, tableView.contentSize.height);
[tableView reloadData];
dispatch_async(dispatch_get_main_queue(), ^{
tableView.contentOffset = offset;
tableView.frame = frame;
});
试过大名鼎鼎的FDTemplateLayoutCell,也拿estimatedHeight没办法。
最终我还是解决了这个问题,但,又很扯,为什么这么说呢→_→ 我在estimatedHeightForRowAtIndexPath里返回的我计算出来的精确高度。。。是的,我最终还是没逃过每种cell都自己计算高度的命运。
所以,使用预估高度的话,不能随便写高度,你轻视它,它就能坑死你。