使用iOS 8.3模拟器和Xcode 6.3.2。
在iOS 8中,我正在使用自动大小单元格技术,当单元格没有附件视图时,它的工作非常出色,但当单元格具有附件视图时,它会出现问题。我在单元格内部设置了标签的约束:
然后我使用estimatedRowHeight
并将rowHeight
设置为UITableViewAutomaticDimension
(这里省略了tableView:numberOfRowsInSection:
,但这个例子中返回3):
@implementation MyTableViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.tableView.estimatedRowHeight = 44.0f;
self.tableView.rowHeight = UITableViewAutomaticDimension;
}
...
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
MyCell *cell = (MyCell *)[tableView dequeueReusableCellWithIdentifier:@"myCell" forIndexPath:indexPath];
cell.titleLabel.text = @"Test comment Test comment Test comment Test comment Test comment Test comment Test comment Test comment Test comment Test comment Test comment ";
return cell;
}
@end
然后,一切看起来都很好:
但是当我在Storyboard中添加一个附件视图时,没有更改任何代码:
第一个单元格就会出现问题。 Xcode的视图调试器告诉我标签高度为1785个点,并且我必须使用gif将其显示在这里:
我确实注意到其他两个单元格大小正常。我还注意到,当我旋转模拟器时,第一个单元格会被正确调整大小,包括在旋转回纵向后。
有人知道为什么附件视图会导致这种严重的问题,以及我该如何解决它吗?示例项目可在http://github.com/UberJason/SelfSizingNightmare找到。