Ios 如何计算UITableViewCell高度查看内容
我需要确定单元格高度和放置在此单元格文本中的位置,其中包含图像,例如: 这里有一些文字 形象 这里有一些文字 形象 ... 发射型计算机断层扫描仪。 如何实现这一点?请推荐。 Thnx。 我想把我的段落分成单独的单元格,如下所示:Ios 如何计算UITableViewCell高度查看内容,ios,objective-c,uitableview,Ios,Objective C,Uitableview,我需要确定单元格高度和放置在此单元格文本中的位置,其中包含图像,例如: 这里有一些文字 形象 这里有一些文字 形象 ... 发射型计算机断层扫描仪。 如何实现这一点?请推荐。 Thnx。 我想把我的段落分成单独的单元格,如下所示: 因为内容是动态的,所以一种方法是在调用heightForRowAtIndexPath(或等效方法)之前计算单元格的高度,并将这些值存储在数组中 -(void)calculateCellHeights:(NSArray *)contentArray { self
因为内容是动态的,所以一种方法是在调用heightForRowAtIndexPath(或等效方法)之前计算单元格的高度,并将这些值存储在数组中
-(void)calculateCellHeights:(NSArray *)contentArray
{
self.heightArray = [[NSMutableArray alloc] initWithCapacity: contentArray.count];
for( MyCellContent *content in contentArray )
{
CGFloat totalHeight = 0;
totalHeight += content.image.size.height;
CGSize titleSize = [content.title sizeWithFont:self.myTitleFont];
totalHeight += titleSize.height;
CGSize textContentSize = [content.textContent sizeWithFont:self.myTextContentFont];
totalHeight += textContentSize.height;
[self.heightArray addObject:@(totalHeight)];
}
}
-(CGFloat) tableView:(UITableView*)tableView heightForRowAtIndexPath:(NSIndexPath*) indexPath
{
return self.heightArray[[indexPath.row floatValue]];
}
这是假设只有一个部分,并且使用常规文本字符串而不是NSAttributed字符串,并且不处理接口元素之间的填充,但您可以了解情况。请澄清。是要获取单元格的高度,还是要计算要放入单元格的内容的高度?