1

In my iOS app (Developing for iOS 7 and up ) I have a UItableViewCellthat calculates it height based on the auto layout constraints I've set and the content of the cell. The code to that works well as for all other cells the height is correct.

However I have a UITableViewCell that only has a UILabel in it and this label gets its text via a web service. So its height needs to be calculated at runtime. This is how I setup the constraints on the UITableViewCell:

enter image description here

So as you can see I expect the UITableViewCell height to be based on the text within the UILabel.

At first the height was too short and my text was cut off. Only after setting preferredMaxLayoutWidth from Automatic to explicit did the height of the cell incase. However how it's seems the hight is too much. Here is what the UITableViewCell now looks like at runtime: Lots of whitespace above and below the UILabel.

enter image description here

Where I am going wrong with my constraints?

halfer
  • 19,824
  • 17
  • 99
  • 186
Robert J. Clegg
  • 7,231
  • 9
  • 47
  • 99
  • http://stackoverflow.com/questions/18746929/using-auto-layout-in-uitableview-for-dynamic-cell-layouts-variable-row-heights – slxl Sep 29 '15 at 09:37
  • Thanks for the link. However I have followed it before and it is how all my other cells work. it just seems this seemly, simple case, with just a UILabel inside it is no working right for some reason. The issue I am having is on iOS 8 as well as iOS7. – Robert J. Clegg Sep 29 '15 at 09:48
  • i did it for a single label for sure. M.. what about set top and bottom to smthng different from 0 and use that approach again? ) – slxl Sep 29 '15 at 09:50
  • That did't solve it. However I found that if I set the cell to the correct width in IB of the smallest width it will have (As my UITableView changes width) then it works correctly. Not sure why this is though. – Robert J. Clegg Sep 29 '15 at 10:56
  • you have to set relations constraints to the label. You have to give greater than or equal to constrant relation to the bottom constraint. Try this way if it works or not – Teja Nandamuri Sep 29 '15 at 11:00
  • Setting the bottom constraint to Grater than or equal gives the cell a little extra space at the bottom. However I am still facing the height issue when the cell is displayed on smaller devices. it seems to cut off on smaller devices and be too tall for bigger screen devices. – Robert J. Clegg Sep 29 '15 at 11:10
  • whats the value in the explicit preffered layout width ? – BangOperator Sep 29 '15 at 11:49
  • 320. The smallest width the tableview will get it. – Robert J. Clegg Sep 29 '15 at 12:01

0 Answers0