第一次加载时某些单元格的UITableViewCell高度错误 [英] Wrong UITableViewCell height for some cells at first loading

本文介绍了第一次加载时某些单元格的UITableViewCell高度错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用UITableViewAutomaticDimension计算我的表格视图单元格的高度.这对我来说可以.但是对于某些单元格,返回的高度为44,而不是动态计算高度.但是,在向上滚动查看同一单元格时,高度可以完美地重新计算.因此,我想我没有任何错误的约束条件,因为在手动滚动并更正所有像元高度后,之后没有显示任何约束突破警告.

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.

修改

下面给出的是图片的屏幕截图(裁剪后会弄乱,但可以从个人资料图片中看到问题.).正确计算了第一个像元高度.但是其余都是错误的.

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.

推荐答案

我添加了以下内容,并且一切正常.

I have added the following and everything worked fine.

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

这篇关于第一次加载时某些单元格的UITableViewCell高度错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆