我正在开发一个在Facebook上加载用户帖子的应用程序。所有这些信息都放入表格 View 中。当您点击它们时,这些单元格将消耗掉。目前只有文字。我计算了文本的高度,所以我知道扩展后单元格需要多高。
我遇到的问题是,其中不仅需要包含文本。如果用户在Facebook上发布视频,该视频也将嵌入到单元格中。但是由于高度是根据文本计算的,因此没有空间容纳嵌入式视频。我可以在单元格中添加边距,但是此边距将应用于所有单元格。
这是我现在正在使用的代码:
//Function executes everything within when a certain row in tapped/selected
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[self.tableView reloadData];
[self stopLoading];
if (selectedIndexPath == indexPath)
{
selectedIndexPath = nil;
}
else
{
selectedIndexPath = indexPath;
}
[self.tableView deselectRowAtIndexPath : indexPath animated : YES];
[tableView beginUpdates];
[tableView endUpdates];
}
//Change heigth of the selected row
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
if ((selectedIndexPath != nil) && (selectedIndexPath.row == indexPath.row))
{
labelSize = [[result2 objectAtIndex:indexPath.row] sizeWithFont:[UIFont fontWithName:@"Helvetica" size:13.0]
constrainedToSize:CGSizeMake(220.0f, MAXFLOAT)
lineBreakMode:UILineBreakModeWordWrap];
return labelSize.height + 136;
}
return 68.0;
}
所以我需要知道。如何根据所有内容计算到单元格的高度?不仅是文字。
如果有人可以帮助您,那就太好了!
提前Thnx
最佳答案
其实..这很简单。只需在heightForRowAtIndexPath中添加以下内容
NSString *video = [fbSource objectAtIndex:indexPath.row] ;
if (video != @"empty") { return labelSize.height + 136; }
return labelSize.height + 36;
关于iphone - 基于内容iOS的动态单元格高度,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/5748309/