UITableViewCell + AutoLayout内容大小未更新

时间:2016-04-19 13:00:34

标签: ios objective-c uitableview autolayout

我正在使用AutoLayout为iOS 7创建一个表格视图 - iOS 9。

我使用 .xib 界面构建器创建了一个单元格原型。

enter image description here

在单元格实现中,我还没有实现。

尽管事实上似乎正确提供AutoLayout约束,但我得到的错误是这样的:

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. 
(
    "<NSLayoutConstraint:0x7fad5a80c3b0 UILabel:0x7fad585a6c60.width == UILabel:0x7fad5ad9f2b0.width>",
    "<NSLayoutConstraint:0x7fad5a84c0a0 UILabel:0x7fad5ad9f2b0.leading == UILabel:0x7fad585a6c60.trailing + 10>",
    "<NSLayoutConstraint:0x7fad5862a140 UILabel:0x7fad585a6c60.leading == MyCustomTableViewCell:0x7fad5ad88560.leading + 10>",
    "<NSLayoutConstraint:0x7fad58621c30 MyCustomTableViewCell:0x7fad5ad88560.trailing == UILabel:0x7fad5ad9f2b0.trailing + 10>",
    "<NSLayoutConstraint:0x7fad5ae218c0 MyCustomTableViewCell:0x7fad5ad88560.width == 1>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x7fad5a84c0a0 UILabel:0x7fad5ad9f2b0.leading == UILabel:0x7fad585a6c60.trailing + 10>

Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.

到达断点时,行[[[0x7fad5ad9f2b0 superview] superview] recursiveDescription]显示:

<VideoAnalysisVideoInformationTableViewCell: 0x7fad5ad88560; baseClass = UITableViewCell; frame = (0 301; 1 35); autoresize = W; layer = <CALayer: 0x7fad585445a0>>
   | <UITableViewCellContentView: 0x7fad585d9d60; frame = (0 0; 1 35); opaque = NO; gestureRecognizers = <NSArray: 0x7fad585a2d30>; layer = <CALayer: 0x7fad585e9b40>>
   |    | <UILabel: 0x7fad585a6c60; frame = (10 5; 145 25); text = 'Score'; opaque = NO; autoresize = RM+BM; userInteractionEnabled = NO; layer =     <_UILabelLayer: 0x7fad5850b030>>
   |    | <UILabel: 0x7fad5ad9f2b0; frame = (165 5; 145 25); text = '33'; opaque = NO; autoresize = RM+BM; userInteractionEnabled = NO; layer = <_UILabelLayer: 0x7fad5ad98210>>
   | <_UITableViewCellSeparatorView: 0x7fad5a8cf620; frame = (15 34; 305 1); layer = <CALayer: 0x7fad5a9121d0>>   

看来内容视图大小不正确。怎么会发生这种情况?我怎么能解决这个问题?

1 个答案:

答案 0 :(得分:0)

你设置了错误的约束。

给出这样的约束,

标题标签 - 领先和顶部

信息标签 - 尾随和顶部

并选择两个标签并给出相等的宽度。希望这会有所帮助:)

更新:

给两个标签顶部,前导,尾随和固定高度。 并给出相等的宽度