在此方法中,計算圖像的高度,每行中使用的文本並將高度作爲浮點值返回。
對於如:
-(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