0

I'm trying to dynamically recalculate the height of the cell that contain UITextView. The height of the cell depends on the height UITextView.

The source code below recalculate height for each cell in table. This is the some text from NSDictionary. After all heights has recalculated I reload my table view with new height that contain in array heightCells;

UITextView *tempTextView = [[UITextView alloc] init];
UIFont *font = [UIFont fontWithName:@"Helvetica" size:16.0];
[tempTextView setFrame:CGRectMake(10, 63, 300, 9999)];
[tempTextView setFont:font];
NSString *str =  [d valueForKey:@"definition"]; // set long text
tempTextView.text = str;
CGRect frame = tempTextView.frame;
frame.size.height = tempTextView.contentSize.height + 20.0;
tempTextView.frame = frame;
[tempTextView sizeToFit];
int height = tempTextView.frame.size.height + 150.0; // set padding 150.0 px
[heightCells addObject:[NSNumber numberWithFloat:height]];

UITableView method:

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return [[heightCells objectAtIndex:indexPath.row] floatValue];
}

On not retina display everything work good and the height recalculated correct, but on retina display I have problem with recalculation. I know that the retina and not retina have one 320x480 points view and it should not affect for recalculation. But in my case this is appear.

Please see screenshot below. As you can see on screenshot the bottom padding after share button a different for retina and not retina display. And I don't know which kind this problem.

retina

not retina

Thanks for help!

Rui Peres
  • 25,741
  • 9
  • 87
  • 137
Matrosov Oleksandr
  • 25,505
  • 44
  • 151
  • 277

1 Answers1

1

It seems the tempTextView's frame differs when it is on the UITableViewCell. I described my working technique in this answer.

Community
  • 1
  • 1
onegray
  • 5,105
  • 1
  • 23
  • 29