【发布时间】:2015-05-21 12:08:54
【问题描述】:
在 iOS 8(和它的 SDK)之前,我使用这个委托方法做了 UITableViewCell 的自动高度:
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
if (!_prototypeCell)
{
_prototypeCell = [tableView dequeueReusableCellWithIdentifier:@"MyShowIdentifier"];
}
EventShow *show = self.myShows[indexPath.row];
self.prototypeCell.categoryNameLabel.text = show.event.category.name;
self.prototypeCell.eventNameLabel.text = show.event.title;
[self.prototypeCell layoutIfNeeded];
CGSize size = [self.prototypeCell.contentView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize];
return size.height + 1.0f;
}
我的单元格有两个标签,一个在另一个之上,带有自动布局约束,告诉标签可以垂直增长。一切正常。
iOS 8 发布后,我仅在第一次使用方法 systemLayoutSizeFittingSize: IS EXECUTED 时收到“无法同时满足约束”错误。委托方法被调用 3 次。这是错误的详细信息:
(
"<NSLayoutConstraint:0x7fd1e8ebce30 H:|-(5)-[UILabel:0x7fd1eb0e00a0'Cine'] (Names: '|':UITableViewCellContentView:0x7fd1eb0c0210 )>",
"<NSLayoutConstraint:0x7fd1eb06b120 H:[UILabel:0x7fd1eb0e00a0'Cine']-(5)-| (Names: '|':UITableViewCellContentView:0x7fd1eb0c0210 )>",
"<NSLayoutConstraint:0x7fd1e8e7be50 'UIView-Encapsulated-Layout-Height' H:[UITableViewCellContentView:0x7fd1eb0c0210(0)]>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x7fd1eb06b120 H:[UILabel:0x7fd1eb0e00a0'Cine']-(5)-| (Names: '|':UITableViewCellContentView:0x7fd1eb0c0210 )>
那里有一个名为“UIView-Encapsulated-Layout-Height”的新约束设置为零。我现在不知道那是什么,但我确定它应该 > 0。
自动高度在 iOS 8 中仍然有效,但它会引发我无法修复的错误。
有什么想法吗?非常感谢!
【问题讨论】:
标签: uitableview ios8 autolayout height