【发布时间】:2015-06-06 19:10:21
【问题描述】:
我探索了关于这个问题的现有问答,但没有找到我的答案。
我知道这是由于 tableview 在运行时不知道自定义单元格的高度造成的,但不知道如何克服这个问题。这是 iOS 8 + Xcode 6。我为自定义单元格的固有大小完成了所有自动布局所需的方法...
-
带有标准单元格的标准表格视图,仅在代码中创建一个(行 = 2)作为自定义单元格;
自定义单元格:
-(CGSize)intrinsicContentSize{ //用于测试目的的硬代码
return CGSizeMake(500.0, 450.0);}
在iOS模拟器上运行时,发现customCell显示在其行下方的其他单元格“下方”,具有高度标准,与其他标准单元格高度的设置方式相同,而不是其高度设置得比其他单元格大得多细胞。
在表格视图控制器中:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell;
pageViewCellTableViewCell* customCell;
if (indexPath.row != 2)
{
cell = [tableView dequeueReusableCellWithIdentifier:@"regularCell" forIndexPath:indexPath];
cell.textLabel.text = [NSString stringWithFormat:@"Table Row %lu", indexPath.row];
return cell;
}
else
{
customCell = [tableView dequeueReusableCellWithIdentifier:@"customCell"] ;
if (customCell == nil) {
customCell = [[customCell alloc] init];
}
customCell.parentViewController = self;
[customCell setNeedsUpdateConstraints];
[customCell setNeedsLayout];
[customCell setNeedsDisplay];
return customCell;
}
return nil ;
}
- (CGFloat)tableView: (UITableView*)tableView EstimatedHeightForRowAtIndexPath: (NSIndexPath*) indexPath
{
if (indexPath.row != 2)
return 10;
else
return 450;
}
- (CGFloat)tableView: (UITableView*)tableView HeightForRowAtIndexPath: (NSIndexPath*) indexPath
{
if (indexPath.row != 2)
return 10;
else
return 450;
}
在模拟器上运行时:
收到以下错误消息: 仅警告一次:检测到约束模糊地建议 tableview 单元格的内容视图高度为零的情况。我们正在考虑意外折叠并改用标准高度。
【问题讨论】:
标签: ios objective-c uitableview