Avisos de layout ambíguo para UILabels no UITableViewCell
Eu tenho doisUILabel
vistas próximas umas das outras em umaUITableViewCell
. A esquerda tem uma linha, a direita pode ter várias linhas e usa o espaço horizontal que resta. Ambos os rótulos têm a mesma distância da parte superior da célula. A altura da célula é ditada pela altura do rótulo correto. Em alguns casos, vejo espaço adicional indesejado acima e abaixo da direitaUILabel
e, portanto, eles não estão alinhados na parte superior. Analisando mais, descobri quehasAmbiguousLayout
retornaYES
para os dois rótulos.
Quando eu ligoconstraintsAffectingLayoutForAxis
no depurador, recebo a seguinte saída:
(lldb) po [0x7b769520 constraintsAffectingLayoutForAxis:0]
<__NSArrayM 0x7b6cb340>(
<NSAutoresizingMaskLayoutConstraint:0x7b76abf0 h=--& v=--& 'UIView-Encapsulated-Layout-Left' H:|-(0)-[UITableViewCellContentView:0x7b768fc0] (Names: '|':MyTVCell:0x7b769330'MyTVCell' )>,
<NSLayoutConstraint:0x7b76b010 H:|-(15)-[UILabel:0x7b769520'Number'] (Names: '|':UITableViewCellContentView:0x7b768fc0 )>,
<NSContentSizeLayoutConstraint:0x7b769a90 H:[UILabel:0x7b769520'Number'(131)] Hug:250 CompressionResistance:750>
)
Por um segundoUILabel
posicionado à direita do primeiroUILabel
, Eu entendi isso:
(lldb) po [0x7b769710 constraintsAffectingLayoutForAxis:0]
<__NSArrayM 0x7b6cb9e0>(
<NSContentSizeLayoutConstraint:0x7b769a90 H:[UILabel:0x7b769520'Number'(131)] Hug:250 CompressionResistance:750>,
<NSAutoresizingMaskLayoutConstraint:0x7b76abf0 h=--& v=--& 'UIView-Encapsulated-Layout-Left' H:|-(0)-[UITableViewCellContentView:0x7b768fc0] (Names: '|':MyTVCell:0x7b769330'MyTVCell' )>,
<NSLayoutConstraint:0x7b76b010 H:|-(15)-[UILabel:0x7b769520'Number'] (Names: '|':UITableViewCellContentView:0x7b768fc0 )>,
<NSLayoutConstraint:0x7b76b230 H:[UILabel:0x7b769520'Number']-(15)-[UILabel:0x7b769710'Q12472']>,
<NSLayoutConstraint:0x7b76ab90 'UIView-Encapsulated-Layout-Width' H:[UITableViewCellContentView:0x7b768fc0(320)]>,
<NSLayoutConstraint:0x7b76b310 UILabel:0x7b769710'Q12472'.trailing == UITableViewCellContentView:0x7b768fc0.trailing - 15>
)
Alguém poderia explicar com base na saída acima por que esses rótulos têm um layout ambíguo?
Atualizar: oNSAutoresizingMaskLayoutConstraint
restrição pertence aocontentView
da célula. Ambos os rótulos definiramtranslatesAutoresizingMaskIntoConstraints
paraNO
.
Atualização 2: Aqui estão as restrições que tenho para o contentView e os dois rótulos:
2015-02-26 07:35:25.559 contentView constraints: (
"<NSLayoutConstraint:0x7be541e0 V:|-(8)-[UILabel:0x7be537d0] (Names: '|':UITableViewCellContentView:0x7be535a0 )>",
"<NSLayoutConstraint:0x7be54240 H:|-(15)-[UILabel:0x7be537d0] (Names: '|':UITableViewCellContentView:0x7be535a0 )>",
"<NSLayoutConstraint:0x7be54310 V:|-(8)-[UILabel:0x7be53990] (Names: '|':UITableViewCellContentView:0x7be535a0 )>",
"<NSLayoutConstraint:0x7be54340 H:[UILabel:0x7be537d0]-(15)-[UILabel:0x7be53990]>",
"<NSLayoutConstraint:0x7be54370 UILabel:0x7be53990.trailing == UITableViewCellContentView:0x7be535a0.trailing - 15>",
"<NSLayoutConstraint:0x7be543c0 UILabel:0x7be53990.bottom == UITableViewCellContentView:0x7be535a0.bottom - 8>",
"<NSContentSizeLayoutConstraint:0x7be53cd0 H:[UILabel:0x7be537d0(109)] Hug:250 CompressionResistance:750>",
"<NSContentSizeLayoutConstraint:0x7be53d10 V:[UILabel:0x7be537d0(21)] Hug:250 CompressionResistance:750>",
"<NSContentSizeLayoutConstraint:0x7be53eb0 H:[UILabel:0x7be53990(20)] Hug:250 CompressionResistance:750>",
"<NSContentSizeLayoutConstraint:0x7be53f10 V:[UILabel:0x7be53990(20)] Hug:250 CompressionResistance:750>"
)
2015-02-26 07:35:25.560 left label constraints: (
"<NSContentSizeLayoutConstraint:0x7be53cd0 H:[UILabel:0x7be537d0(109)] Hug:250 CompressionResistance:750>",
"<NSContentSizeLayoutConstraint:0x7be53d10 V:[UILabel:0x7be537d0(21)] Hug:250 CompressionResistance:750>"
)
2015-02-26 07:35:25.561 right label constraints:(
"<NSContentSizeLayoutConstraint:0x7be53eb0 H:[UILabel:0x7be53990(20)] Hug:250 CompressionResistance:750>",
"<NSContentSizeLayoutConstraint:0x7be53f10 V:[UILabel:0x7be53990(20)] Hug:250 CompressionResistance:750>"
)
Aqui está uma imagem mostrando as restrições que tenho e o que dá errado: