dynamicuitableview细胞高度

我从asynchronousjson服务器获取数据,我把它们放在我的表格视图单元格。我试图根据文本内容dynamic的基础上使单元格的高度。 我在互联网上发现了它,但是在任何地方都给出了相同的代码,

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

我没有得到如何实现this.Please指导我。

在这个方法中,计算图像的高度,在每行中使用的文本,并将高度作为浮点值返回。

例如:

 -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { float totalHeight = 0.0; BOOL ImageToBeDisplayed = [[yourDataArray objectAtIndex:indexPath.row]objectForKey@"yourImageKey"]; if(ImageToBeDisplayed) totalHeight = 100 or some value of your choice } else{ //Do nothing } If your row has string data as well. int length = [[[yourDataArray objectAtIndex:indexPath.row]objectForKey@"yourTextKey"] length]; if(length<40) totalHeight + = 50; else if (length<80 && length>40) totalHeight + = 100; and so on and return totalHeight; }