AutoLayout constraint issue with unexpected NSAutoresizingMaskLayoutConstraint

后端 未结 2 1254
灰色年华
灰色年华 2021-01-04 04:19

I\'m using auto layout constraints programmatically and I am constantly seeing the same kind of error across my application usually related to a constraint that looks like t

2条回答
  •  清酒与你
    2021-01-04 05:08

    You should read the exception description more thoroughly:

    Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints
    

    In short, this constraint you are seeing is due to some UIView having it's translatesAutoresizingMaskIntoConstraints set to YES. In this case I would suspect this is the content view of the cell, as hinted to by UITableViewCellContentView.

    You can disable it by just setting the property to NO.

    cell.contentView.translatesAutoresizingMaskIntoConstraints = NO
    

    EDIT: Now, keep in mind that this is a temporary fix, most likely you have some other logic error with your constraints, for example constraining something in the contentView of the cell to the cell itself. Or by seemingly forcing the contentView to be larger than the cell is (and therefore larger than its' automatic sizing is).

    For example, is your cell tall enough? i.e is it tall enough so that the contentView is 100pt tall? Note that the contentView has to be that tall, which might not necessarily match the height of the cell.

提交回复
热议问题