2014-11-17 70 views
1

我只有一个按钮的单元格,我已经添加了button = 30,top = 10和bottom = 10约束的高度,所以systemLayoutSizeFittingSize必须返回单元格高度= 50。返回50.5,我在日志中看到:UITableViewCell systemLayoutSizeFittingSize增加了额外的0.5 px

Will attempt to recover by breaking constraint 

我正在使用分组表格视图和分隔符设置为无。哪里需要额外的0.5px?

constraints

代码片段:

[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)]> 
+1

请你可以显示整个错误日志。它会显示正在发生的事情。 – Fogmeister

+1

你的目标是iOS8吗? – Fogmeister

+0

7+我知道有细胞高度在8 ..辉煌的解决方案..但我们需要7. – trickster77777

回答

3

的iOS 8

如果你的目标是iOS8上那么它使得作为表视图这更简单现在可以将单元格大小设置为automag由AutoLayout完成。

要做到这一点只需在您的heightForRow方法返回UITableViewAutomaticDimension ......

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    return UITableViewAutomaticDimension; 
} 

本质上讲,这做什么,我想你想你的代码片段做。

的iOS 7

对于iOS 7我想不同的设定了限制。而不是设置顶部和底部的约束,我只是有一个“中心垂直”约束。

然后你可以返回你想要返回的任何数字,并且约束不会中断。

你没有得到自动高度的东西,但高度似乎并没有改变。

+0

我的目标是7.谢谢你指出我不会改变的事实。但它真的很有趣,它需要额外的0.5 – trickster77777

+0

@ trickster77777是的,AutoLayout有时会很奇怪,而且我自己也看到过类似的东西。我想这是因为它不能放置在0.5像素或什么东西。不知道为什么它需要通过? – Fogmeister

+0

如果我记得0.5是细胞分离器的大小,并且总是添加到细胞高度。 –