views:

53

answers:

1

I am interested in creating a UITableViewCell with a UITextView inside of it, which adjusts its height (to a certain maximum) as the user types more or less text into the UITextView. I know how to add the UITextView to a custom UITableViewCell--but how might I change the UITableViewCell's height as the user is in the process of typing? Is this possible to do?

+2  A: 

As far as I know the only way to set the height of a table cell is through the delegate heightForRowAtIndexPath: method. To invoke this method you can call reloadData on the table but I'm not sure what effect that would have on the UITextView you are editing. Worth a try though.

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {

return 100;
}

To calculate the return value you would need to work out the height based on the current input and expand the text view at the same time. NSString has some helpful methods for this such as sizeWithFont:constrainedToSize:lineBreakMode:. It will work out a CGSize you can use to make your CGRect etc.

Ben
feloadData will cause the cell to get reloaded and the keyboard will get removed.
schwa