具有自动布局功能的IOS Self Sizing UITableViewCell首次无法正常工作

时间:2015-01-25 08:43:10

标签: ios objective-c xcode uitableview

我正在尝试通过自动布局实现自动调整大小UITableViewCell。我有Table View Prototype单元格(Custom Cell)。

我有一个UIImageView,它有TopSpace,BottomSpace,LeadingSpace来查看,Height&宽度为约束。

我有UILabel,它有UIIMage的顶部水平空间查看尾随空间以查看底部的UILabel和垂直空间。

我有另一个UILabel,它有水平空间到UIImage查看尾随空间来查看和底部空间。

我已将Lines设置为0.对于标签和添加的

self.tblview.estimatedRowHeight = 80.0f; self.tblview.rowHeight = UITableViewAutomaticDimension;

我在cellForRowAtIndexPath

中也有以下代码

[cell setNeedsUpdateConstraints]; [cell updateConstraintsIfNeeded]; [cell setNeedsLayout];

这不是第一次工作,但当我向下滚动并向上滚动时,自动调整大小就像魅力一样。

任何人都可以帮助我吗?

1 个答案:

答案 0 :(得分:0)

您可以添加此

[cell layoutIfNeeded];

之后

[cell setNeedsLayout];

它可能有用。