间接的方法:使用
设置你的UITableViewCell的自定义高度
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return [indexPath row] * 40;
}
找到行的程序点总数...使用numberOfRowsInSection,得到数的行。
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [self.yourArray count];
//yourArray is the array with which you are populating the tableView
}
如果您有多个节,请将其与有效行数的行数结果相乘。
现在
UITableView Actual Height = Height of UITableViewCell * Total number of rows.
更新答:
如果单元格大小各不相同,你可能需要做执行下列操作之一:
强制文本到一个较小的使所有细胞具有相同的高度...这可以使用
'sizeToFit'
您将不得不使用另一个函数来查找文本的高度。喜欢的东西...
- (浮动)calculatedHeight { 回报textLabel.frame.origin.ytextLabel.frame.size.height5; }
你可以看一下THIS教程调整UITableViewCell的可变文本。
https://discussions.apple.com/thread/1525150?start=0&tstart=0
不幸的是,我的单元格根据它们携带的内容而具有不同的高度,我无法用'noOfRows * cellHeight'预先计算高度。 – 2011-06-10 23:05:39
检查更新的答案。 – Legolas 2011-06-10 23:15:26