3
votes

I am trying to implement auto resizing UITableViewCell by auto layout. I have Table View Prototype cell (Custom Cell).

I have one UIImageView which has TopSpace, BottomSpace, LeadingSpace to view, Height & Width as constraints.

I have UILabel Which has Top, Horizontal space to UIIMage View Trailing Space to view and vertical space to UILabel at bottom.

I have another UILabel which has Horizontal Space to UIImage View Trailing space to view and bottom space.

I have set Lines to 0. for both label and added

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

Also i have following code in cellForRowAtIndexPath

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

This is not working for first time but when i scroll down and scroll up auto sizing works like a charm.

Can any one please help me here ?

1
The fix is probably remove the first two lines in your post, and uncheck preferredMaxLayoutWidth for the label in storyboard. - gabbler
Than there would be no auto re sizing in uitableviewcell - Aadil Keshwani
Sharing your project would be great, because it is not reproducible for me. - gabbler
are the steps perfect for making uitableviewcell autoresizable ? If you have any new way please share. - Aadil Keshwani

1 Answers

0
votes

You can add this

[cell layoutIfNeeded];

after

[cell setNeedsLayout];

It may works.