问题
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