iOS8 - constraints ambiguously suggest a height of zero

前端 未结 18 1827
青春惊慌失措
青春惊慌失措 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:37

    If you're using autoLayout constraints and UITableViewAutomaticDimension, this error is not some erroneous problem to be discarded by overriding your height in code. It means that determining the cell height automatically isn't working because you don't have the proper vertical constraints needed.

    If you're like me and were getting this error and needed help identifying which cell was throwing the error, you can add the following line right before the return of your 'heightforRowAtIndexPath' method.

    NSLog(@"Section %ld Row %ld", (long)[indexPath section], (long)[indexPath row]);
    

    This will print out a long list of sections and rows, but the error will appear immediately following the particular cell that is causing the error, and you can quickly identify which cell is causing the problem and fix your constraints accordingly. This is particularly helpful for static cells. Overriding the height with a manually entered number will work if you're not using autoLayout and automatic cell heights, but will essentially disable these features which is a very poor solution if its something you're trying to utilize.

    If you weren't previously using the 'heightForRowAtIndexPath' method but want to debug this error without undoing your UITableViewAutomaticDimension setting, simply add this to your code:

    - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
        NSLog(@"Section %ld Row %ld", (long)[indexPath section], (long)[indexPath row]);
        return UITableViewAutomaticDimension;
    }
    

提交回复
热议问题