UITableView的cell 動態 定義 高度

2021-06-13 01:45:30 字數 1110 閱讀 2795

**

首先在uitableview 的**方法中算出每個cell 的真實高度,然後設定便ok。如下:

[html]view plain

copy

- (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath  

cgrect cellframe = [newscell frame]; //定義的cell 的 frame  

cellframe.origin = cgpointmake(0,0);  

uilabel *productlabel31=(uilabel *)[newscell.contentview viewwithtag:111143];  

if (!productlabel31)   

cell = newscell;  

cellframe.size.height = productlabel31.frame.origin.y+productlabel31.frame.size.height +2; // 改變cell 的frame  

[cell setframe: cellframe]; // 改變cell 的frame  

}  cell.selectionstyle=uitableviewcellselectionstylenone;  

return cell;  

}  

最後 還要在

uitableview 的**方法heightforrowatindexpath中設定下cell 的高度:

[html]view plain

copy

- (cgfloat)tableview:(uitableview *)tableview heightforrowatindexpath:(nsindexpath *)indexpath  

這樣cell就可以伴隨你cell 內容的多少而 任意改變高度了。 

效果:

iOS7中UITableView中cell的使用

今天看到很多人提到,在ios7中,使用uitableview的時候,對於cell要注意 cell addsubview usertextfield 這種用法不能再用了,應該使用 cell.contentview addsubview usertextfield 的方式。如某人就遇到這種問題 調查了一...

iOS7中UITableView中cell的使用

分類 ios oc 2013 09 26 15 01 3099人閱讀收藏 舉報 今天看到很多人提到,在ios7中,使用uitableview的時候,對於cell要注意 cell addsubview usertextfield 這種用法不能再用了,應該使用 cell.contentview adds...

關於tableview不能全部顯示cell的問題?

今天遇到乙個問題,在uiview上新增乙個tableview的字控制項,可是頁面做完之後發現cell不能全部顯示 各種嘗試 1.以為彈力問題,就把彈簧效果去掉不行。2.還以為是重用機制問題 最後發現,是tableview的frame的問題 因為tableview的frame超出了螢幕,所以cell也...