1

I am loading data into a UITableviewcell from a server and the problem is that sometimes the text returned is large and sometimes less . Now the problem is when large text is returned , the tableview cell is not able to display the whole data , and when the text returned is small , then there is a blank space in the cell which does not look good.

Can someone help me in this matter please ?

John
  • 29
  • 3
  • Hey, check out - tableView:heightForRowAtIndexPath: of UITableViewDelegate and this http://stackoverflow.com/questions/3429671/how-to-get-the-width-of-an-nsstring – Sascha Manuel Hameister May 29 '15 at 20:02

3 Answers3

0

If the text is being displayed in a UITextView, you can use the sizeThatFits() method or contentSize property to determine the size of the text. You can do this in the UITableViewDelegate method tableView:heightForRowAtIndexPath: to apply the size of the text to the UITableViewCell.

keithbhunter
  • 12,258
  • 4
  • 33
  • 58
0

Use the property estimatedRowHeight for tableView in iOS 8.

    self.tableView.estimatedRowHeight = 100;
Mahi
  • 181
  • 1
  • 7
0

Don't do your own height calculations. Let Auto Layout (and self-sizing cells) do the work.

Here's an excellent walkthrough covering what to do, from a similar question.

Community
  • 1
  • 1