iOS8 - constraints ambiguously suggest a height of

2019-01-10 11:40发布

Has anyone got any idea how to debug this?

Warning once only: Detected a case where constraints ambiguously suggest a height of zero for a tableview cell's content view. We're considering the collapse unintentional and using standard height instead.

The rows have a fixed height as set by

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

And all the constraints seem to be happy...

17条回答
Melony?
2楼-- · 2019-01-10 12:17

There appears to be a bug in XCode 6.1 that causes this problem if using auto-layout and you don't specify a value for the Row Height for each Table View Cell, but instead you leave the "default" value. Simply checking the "Custom" checkbox next to the Row Height, for every cell, makes the warning go away.

查看更多
一夜七次
3楼-- · 2019-01-10 12:19

Yes, You get all constrains "happy" even in case when you only have horizontal constrains for items in table view cell. I had same issue. You need to add also vertical constrains. Doing so, that warning will go away.

查看更多
放我归山
4楼-- · 2019-01-10 12:19

The constraints can be happy for the purpose of layout, but not happy for the purpose of automatic row height. A happy layout would mean the content can be laid out without ambiguity. That would satisfy the checks in Interface Builder.

A happy layout for automatic row height would mean that, in addition to the above, you're also including constraints to the bottom of the cell.

More here: Detected a case where constraints ambiguously suggest a height of zero

查看更多
叼着烟拽天下
5楼-- · 2019-01-10 12:20

You can use AutoLayout to calculate the right height for you. Here is a nice post about Dynamic Cell Height on iOS 8: http://natashatherobot.com/ios-8-self-sizing-table-view-cells-with-dynamic-type/

查看更多
The star\"
6楼-- · 2019-01-10 12:23

In my case, it is because I'm designing the cell with xib, and I forget to add that xib file to the target.

After I add that xib file to the target, the problem is gone

查看更多
Anthone
7楼-- · 2019-01-10 12:25

There are two important things happening here, I think.

1) It's super easy to make the constraints wrong if you're ctrl+dragging. So, double check that you have it done correctly. Best to use the tray on the left side of the screen to draw these constraints.

2) Instead of specifying the estimatedRowHeight in ViewDidLoad or somewhere else, use the delegate method

override func tableView(tableView: UITableView, estimatedHeightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {}

This fixed the problem right away for me.

查看更多
登录 后发表回答