3

I cannot get the real height of a UITextView after trying the suggestion in the forums like:

How do I size a UITextView to its content?

Resizing UITextView

This solution make the UItextView resize to its content, but I need to know the real height of the UItextView so I can position the rest of views without overlapping.

I have a UITableView each cell displays an UITextView.

I get the size of the UITextView, resize it and resize the cell containing it with the following code:

//self.descriptionTV is a UITextView
self.descripcionTV.text = self.detailItem.descripcion;

//I calculate the height (altura) to size the UITextView and to later size the cell
NSNumber *altura = [NSNumber numberWithFloat:
                            (self.descripcionTV.contentInset.top + self.descripcionTV.contentSize.height + self.descripcionTV.contentInset.bottom)];            

//Here I size the UITextView        
CGRect frame = self.descripcionTV.frame;
frame.size.height = altura.floatValue;
self.descripcionTV.frame = frame;



 //I use this in tableView:heightForRowAtIndexPath:
 [self.cellsToLoad addObject:[NSArray arrayWithObjects:self.cellDescripcion, altura, nil]];

-(float)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    //La altura de la celda la tenemos almacenada en el array cells
    float altura = [[[self.cellsToLoad objectAtIndex:indexPath.row] objectAtIndex:1] floatValue];
    return altura;
}

Unfortunatelly this does not get the job done. The Cell after this gets overlapped by some pixels. I have been using UILabel instead of UITextViews before with no problem.

I know a solution is just to increment manually the height calculated, but I would like to know if there is a real method for getting the size of a UITextView.

Community
  • 1
  • 1
David Casillas
  • 1,801
  • 1
  • 29
  • 57

0 Answers0