解决使用了estimatedHeight导致的tableView reloadData乱跳

这是通常情况下我们用来解决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都自己计算高度的命运。

所以,使用预估高度的话,不能随便写高度,你轻视它,它就能坑死你。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值