【发布时间】:2015-06-25 17:24:07
【问题描述】:
使用 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
然后 bam,一切看起来都很棒:
但是当我在情节提要中添加附件视图时,无需更改任何代码:
第一个牢房下地狱。 Xcode 的视图调试器告诉我标签高度是 1785 点,我不得不在这里使用 gif 来显示它:
我确实注意到其他两个单元格的大小很好。我还注意到,当我旋转模拟器时,第一个单元格会正确调整大小,包括在它旋转回纵向之后。
有谁知道为什么附件视图会如此糟糕,以及我能做些什么来解决它? http://github.com/UberJason/SelfSizingNightmare 提供示例项目。
【问题讨论】:
标签: ios iphone uitableview ios8