I have a custom table cell that contains 3 labels, a button, and a UITextView.

The text for the UITextView is only known at runtime as it's data I'm pulling from a server.

I'm trying to size both my UITextView and my Custom Table Cell to the correct height based on the text that I put into the UITextView.

The text for the UITextView gets set in the - (UITableViewCell \*)tableView:(UITableView \*)tableView cellForRowAtIndexPath:(NSIndexPath \*)indexPath method.

In here I'm trying to size the UITextView (bodyTextView) using the following..

```
CGSize stringSize = [cell.bodyTextView.text sizeWithFont:cell.bodyTextView.font constrainedToSize:CGSizeMake(cell.bodyTextView.bounds.size.width, 9999) lineBreakMode:NSLineBreakByWordWrapping];

[cell.bodyTextView setText:threadMessage.body];

CGRect bodyFrame = cell.bodyTextView.frame;

bodyFrame.size = cell.bodyTextView.contentSize;

[cell.bodyTextView setFrame:bodyFrame];

```

That more or less seems to be working fine either that my UIButton isn't moving down to where it should even though it has a "Top Space To" constraint to the bottom of my UITextView. I would've thought that it would've automatically moved. However I can move this to the appropriate location programatically so not a big deal. 

The next bit of code does size the tableViewCell to the appropriate height to fit in the labels and the UITextView but there isn't enough space for the button at the bottom.
Next I calcuate the height of the cell and return it using the following...

```
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath: (NSIndexPath *)indexPath
{
    CGSize stringSize = [threadMessage.body sizeWithFont:[UIFont systemFontOfSize:14] constrainedToSize:CGSizeMake(280, 9999) lineBreakMode:NSLineBreakByWordWrapping];

    float oldHeight = 28;
    float newHeight = stringSize.height;

    return tableView.rowHeight - oldHeight + newHeight;
}

```

As you can see I'm doing a difference in height between what the UITextView height was and what the new one is. I tried to get the oldHeight programatically but I was getting crazy values in the many thousands.

The big problem is that when the view first shows, the row is sized, more or less, correctly. But the UITextView isn't sized. If I scroll to move it off screen and then scroll it back then the UITextView is sized properly. But then again if I scroll it off and back on screen it's resized itself again to a single line.

I feel I have a chicken or the egg thing going on and can't get my head around this.

The two main issues I'm hoping to get figured out are :

1 ) How to get the UITextView to size properly right from the start and stay that way regardless of scrolling off and on screen?

2 ) How to get my custom TableCellView to size appropriately to include the height of the button?

I hope this all makes sense and I've provided enough detail. Let me know of any questions.

Any suggestions would be very much appreciated. Thank you!

Regards,

Peter