【发布时间】:2014-11-17 11:12:15
【问题描述】:
我的单元格中只有一个按钮,我添加了按钮高度 = 30、顶部 = 10 和底部 = 10 约束,因此 systemLayoutSizeFittingSize 必须返回单元格高度 = 50。但它返回 50.5,我看到日志:
Will attempt to recover by breaking constraint
我正在使用分组表视图并将分隔符设置为无。哪里需要额外的 0.5px?
代码sn-p:
[cell layoutSubviews];
return [cell systemLayoutSizeFittingSize:UILayoutFittingCompressedSize].height;// 50;
日志:
Unable to simultaneously satisfy constraints.
Probably at least one of the constraints in the following list is one you don't want. Try this: (1) look at each constraint and try to figure out which you don't expect; (2) find the code that added the unwanted constraint or constraints and fix it. (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints)
(
"<NSLayoutConstraint:0x7ffa71e273e0 V:[UIButton:0x7ffa71e24900'Book a new hotel'(30)]>",
"<NSLayoutConstraint:0x7ffa71e20bc0 V:|-(10)-[UIButton:0x7ffa71e24900'Book a new hotel'] (Names: '|':UITableViewCellContentView:0x7ffa71e06030 )>",
"<NSLayoutConstraint:0x7ffa71e23ae0 UITableViewCellContentView:0x7ffa71e06030.bottomMargin == UIButton:0x7ffa71e24900'Book a new hotel'.bottom + 2>",
"<NSLayoutConstraint:0x7ffa705f6640 'UIView-Encapsulated-Layout-Height' V:[UITableViewCellContentView:0x7ffa71e06030(50.5)]>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x7ffa71e273e0 V:[UIButton:0x7ffa71e24900'Book a new hotel'(30)]>
【问题讨论】:
-
请您显示整个错误日志。它会显示正在发生的事情。
-
你的目标是iOS8吗?
-
7+ 我知道 8.. 单元格高度有很好的解决方案,但我们需要 7.
-
我觉得应该是
[cell.contentView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize].height + 1; -
你说得对,它应该是 cell.contentView,而不是 cell。而且不用加“1”。
标签: ios objective-c uitableview autolayout