在此方法中,计算图像的高度,每行中使用的文本并将高度作为浮点值返回。
对于如:
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
float totalHeight = 0.0;
BOOL ImageToBeDisplayed = [[yourDataArray objectAtIndex:indexPath.row][email protected]"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][email protected]"yourTextKey"] length];
if(length<40)
totalHeight + = 50;
else if (length<80 && length>40)
totalHeight + = 100;
and so on
and
return totalHeight;
}
感谢琼斯:-) – codejunkie
为什么有硬编码常数?如果字体大小发生变化怎么办? – mskw