Wrong UITableViewCell height for some cells at first loading

↘锁芯ラ 提交于 2020-06-25 04:58:28

问题


I am using UITableViewAutomaticDimension to calculate height for my table view cell. It works fine for me. But for some cells, the height returned is 44 rather than dynamically calculating height. But on scrolling up an looking back to the same cell, the height is recalculated perfectly. So I guess I do not have any faulty constraints because, after I scroll and correct all cell heights manually, no constraint breaking warning are shown afterwards.

Edit

The below given is the screenshot of image(got messed up when cropped, but can see the issue from the profile image.). The first cell height is calculated correctly. But the rest are faulty.


回答1:


I have added the following and everything worked fine.

(CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return UITableViewAutomaticDimension;
}



回答2:


In my case it was something wrong with layoutMarginsGuide top and bottom anchor. I use it for cell subviews and set preservesSuperviewLayoutMargins = true for its subviews. This caused the mistake when system tried use systemLayoutSizeFitting to calculate cells height first time.



来源:https://stackoverflow.com/questions/32688709/wrong-uitableviewcell-height-for-some-cells-at-first-loading

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!