1

I'm trying to solve this Auto Layout puzzle with a custom UITableViewCell which contains two labels that may grow vertically depending on their content i.e. number of lines. I've almost got it right, except that one label in one cell does not grow as expected! Please see screenshot where highlighted in red dashed line – the label does not end with a bracket, its text is clipped instead.

enter image description hereenter image description here Please find the simple Xcode project here.

Captain Obvlious
  • 19,754
  • 5
  • 44
  • 74
StackUnderflow
  • 2,403
  • 2
  • 21
  • 28
  • 2
    I've tried this before, this might be an iOS bug. If you scroll it offscreen and go back, it is automatically fixed. – Schemetrical May 23 '15 at 23:43
  • 1
    Check this big post with examples http://stackoverflow.com/questions/18746929/using-auto-layout-in-uitableview-for-dynamic-cell-layouts-variable-row-heights – aquarium_moose May 24 '15 at 09:18

1 Answers1

3

In my case there are two multiline labels and not just one as in other posts, and so there are 2 elements that effect the height of a cell. But regardlesss of that the soluion is to force the cell to do its layout. So after calling dequeueReusableCellWithIdentifier() to get the cell, just add:

// fix for iOS lauout bug
cell.setNeedsLayout()
cell.layoutIfNeeded()

All starting and ending brackets are visible i.e. to text clipping :-) enter image description here

StackUnderflow
  • 2,403
  • 2
  • 21
  • 28