Detected a case where constraints ambiguously suggest a height of zero

后端 未结 23 703
猫巷女王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:18

    In my case, I was building the cell programmatically and kept getting this error.

    I was adding the subviews and constraints in the UITableViewCell's init method like this:

    addSubview(rankingLabel)
    addConstraints(cellConstraints)
    

    I solved the issue by adding them to the cell's contentView instead:

    contentView.addSubview(rankingLabel)
    contentView.addConstraints(cellConstraints)
    
    0 讨论(0)
  • 2020-12-07 10:18

    In the storyboard set the cell Row height field with the same value as Row height in tableView (both with the same value worked for me).

    If you add heightForRowAtIndexPath function to your code it may induce a performance issue because it will be called for each cell so be careful.

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

    This is an autolayout issue. Make sure that your subviews have all the constraints. For me, the bottom constraint was missing for the Title Label in the cell. When I added that, the warning went away and everything showed up perfectly.

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

    If u are using static cell or dynamic cell ,simply add some row height to table view in inspector table and uncheck the automatic to the right side of row height ,that's it u will stop getting this warning .

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

    I got this Warning today All I did is just added one extra line to my code

    tableView.rowHeight = 200;
    

    add this line of code inside the

    func tableView(_ tableView: UITableView, numberOfRowsInSection section:Int) -> Int {
      ...
    }
    

    and the final code look like

    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
      tableView.rowHeight = 200;
      ...
    }
    

    this code will increase the table Row cell height to 200 the default height is 44

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