I’m having some trouble here.
I’ve got a tableview, with 7 cells, all of them are made using .xib-files. Some of them contain labels, two contain a textview.
The current situation is that all the labels are shown correctly. The height of the cells are the same as the .xib-file states.
The problem is, the textviews are acting up strange. It might have to do something with the fact that I want them to be dynamic. Sometimes, it gives a long story in that textview. Sometimes, only one word. Therefore, the textview should be dynamic, and so should the cell’s height be.
The code looks like this:
DetLocDescrCell *locDCel = (DetLocDescrCell *)[tabelView dequeueReusableCellWithIdentifier:nil];
if (locDCel == nil) {
[[NSBundle mainBundle] loadNibNamed:@"DetLocDescrCell" owner:self options:nil];
locDCel = detLocDescrCell;
}
[locDCel.locDescrLabel setText:[geselecteerdItem objectForKey:@"LocationDescription"]];
CGRect descrFrame;
descrFrame = locDCel.locDescrLabel.frame;
descrFrame.size.height = [locDCel.locDescrLabel contentSize].height;
locDCel.locDescrLabel.frame = descrFrame;
descrFrame.size.height = descrFrame.size.height + 10;
locDCel.frame = descrFrame;
[listCells addObject:locDCel];
This code creates a custom cell from the class DetLocDescrCell, loads the data, check whenever the height should be adapted or not, adapts the height, then adds the cell to the list of cells. The list of cells is used again in cellForRowAtIndexPath and heightForRowAtIndexPath. But, the height isn’t adapted, and the textviews aren’t getting the correct text. Does anyone have any idea?
i m not sure whether this is the right way , but i done this way,
The situation is custom cell height & heightforrowatindex cell’s height should be same so i tried
calculate the height of textview content in heightforrowatindexpath
then in your cellforrowatindexpath – calculate the same height & initalize height to custom cell textview’s height
cell.txtView.frame = CGRectMake (10,10,190,txtsize.height).then both u r txtview height & cell height will be equal
Hope this idea helps!