iOS8 - constraints ambiguously suggest a height of zero

前端 未结 18 1692
青春惊慌失措
青春惊慌失措 2020-12-02 14:15

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 c

相关标签:
18条回答
  • 2020-12-02 14:39

    For a bog standard fix, no constraints, no estimating heights, or over engineering the problem. I created a default project, wired up the tableview but forgot to put the height delegate in the view controller. To simply make this warning go away you need this.

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

    In your table's view controller.

    0 讨论(0)
  • 2020-12-02 14:43

    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.

    0 讨论(0)
  • 2020-12-02 14:47

    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

    0 讨论(0)
  • 2020-12-02 14:49

    In Swift forcing a return height fixed my problem:

    override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
        if(indexPath.row == 0){
           return CGFloat(131.0)
        }else if(indexPath.row == 8){
           return CGFloat(97.0)
        }else{
           return CGFloat(44.0)
        }
    }
    
    0 讨论(0)
  • 2020-12-02 14:49

    I was using a mapView inside uitableviewcell. I changed the height of map view to 1/3th of the device screen size. I got the same error. I fixed the error by adding missing constraints to the content view of the uitableviewcell.

    1) Clear the contentView constraints.

    2) Set Reset to Suggested constants to contentView.

    3) Add missing constraints - if any

    4) We make sure the content view has all the required constraints.

    0 讨论(0)
  • 2020-12-02 14:51

    I couldn't get to remove the warning, but to make constraints work I set the ,new to iOS8 , tableview property estimatedRowHeight to the fixed height, and removed heightForRowAtIndexPath implementation.

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