Detected a case where constraints ambiguously suggest a height of zero

后端 未结 23 701
猫巷女王i
猫巷女王i 2020-12-07 09:31

After updating to Xcode 6.1 beta 2 when I run my app that contains tableview cells, the debug assistant says:

Warning once only: Detected a case where constr         


        
相关标签:
23条回答
  • 2020-12-07 10:07

    Just enable Self-Sizing Table View Cells

       tableView.estimatedRowHeight = 85.0
       tableView.rowHeight = UITableViewAutomaticDimension
    

    & make sure you added constraints on all sides of UITableViewCell as-

    • Example Link 1

    • Example Link 2

    0 讨论(0)
  • 2020-12-07 10:08

    To resolve this without a programmatic method, adjust the row height of the table view in the Size Inspector from the storyboard.

    enter image description here

    0 讨论(0)
  • 2020-12-07 10:10

    I too experienced this warning with moving to Xcode 6 GM. I was only getting the warning when I rotated the device back to its original position.

    I am using custom UITableViewCells. The storyboard table view is set to my custom size (100.0 in my case). While the table cells render properly as they have in previous releases, I did not like warning message.

    In addition to the above ideas, I added this

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

    Screen renders... responds to rotation and no more warning messages.

    0 讨论(0)
  • 2020-12-07 10:12

    If you have created a Custom tableViewCell for tableView, make sure you have given both bottom and top constraints to you cells, you could also get this message if your subviews inside custom cells are aligned in center Y which wouldnt pop any error message but would mess up with identifying height of row for tableview in turn like in Image I have attached , here we have both top and bottom constraints

    When you create a Custom Cell for tableView you must specific row height or top and bottom constraints for you custom cell's subviews inside cell (e.g. label in custom cell like in below image)

    But if this doesn't work you can try setting row height for your cell instead of being automatic like in this image

    But be sure if you turn that automatic tick off you have to adjust your row size for changes programmatically which could have been done automatically

    0 讨论(0)
  • 2020-12-07 10:12

    I had this problem when my labels and views in the custom tableViewCell were constrained to the customCell, not its Content View. When I cleared the constraints and connected them to cells Content View the problem was solved.

    0 讨论(0)
  • 2020-12-07 10:13

    Set the estimated row height to zero and the warning disappears:

    0 讨论(0)
提交回复
热议问题