I'm trying to resize a UITextView that I have in a UITableViewCell. I want to resize the UITableViewCell accordingly also. My UITableViewCell resizes properly, but the UITextView does not. It ends up being just two lines instead of sizing to the the correct size. When I initialize it in the cellForRowAtIndexPath method, it looks like:
UITextView *notesTextView = [[UITextView alloc] initWithFrame:CGRectMake(83, 12, TEXTVIEW_WIDTH, 22)];
notesTextView.tag = TEXTVIEW_TAG;
notesTextView.delegate = self;
[cell.contentView addSubview:notesTextView];
When I try to modify it in the textView delegate method, I do:
CGSize size = [textView.text sizeWithFont:textView.font constrainedToSize:CGSizeMake(TEXTVIEW_WIDTH, 460) lineBreakMode:UILineBreakModeWordWrap];
NSLog(@"size: %@", NSStringFromCGSize(size)); // has the correct size
if (size.height > self.notesRowHeight) {
self.notesRowHeight = size.height;
UITextView *aTextView = (UITextView *)[self.view viewWithTag:TEXTVIEW_TAG];
CGRect textViewFrame = CGRectMake(aTextView.frame.origin.x, aTextView.frame.origin.y, TEXTVIEW_WIDTH, size.height);
aTextView.frame = textViewFrame;
aTextView.contentSize = size;
[aTextView sizeToFit];
[aTextView sizeThatFits:size];
NSLog(@"%@", NSStringFromCGRect(aTextView.frame)); // has the correct height
So what ends up happening is the tableView resize properly, and even though the textView frame is the correct size (e.g. {{83, 12}, {197, 120}}), the textView only has 2 lines. It does not end up taking the size of the UITableViewCell like I intended.
EDIT: When I try to just resize the frame for the UITextView in a normal UIView that is not a UITableViewCell, it works just fine. So I'm not sure what's different in this case.