gpt4 book ai didi

swift - TableView 单元格中的约束似乎被忽略了

转载 作者:行者123 更新时间:2023-11-28 05:55:48 24 4
gpt4 key购买 nike

我无法让这些 slider 对齐,我不确定为什么。

sliders on wrong side

这是我的 Storyboard ……尾随约束显然被忽略了。我做错了什么?

storyboard

编辑:对于马特:

我删除了所有约束

并按住控制键拖动其中两个,这应该已经足够了:trailing: 14center Y(现在在 superview 上,rhs 标签在错误)。任何绘制的约束都没有“在运行时删除”。

View debugging showing issue flags

标志是可见的,但没有指示它们的含义(尺寸检查器无益地只说“具有不明确的约束”)。

编辑#2

根据此处的输入和 swift discord 中的信息,这是应用了更改的 View 示例:

rebuilt result这是该 Storyboard的相关 xml:

                                    <tableViewCell clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleToFill" restorationIdentifier="RootAppCell" preservesSuperviewLayoutMargins="YES" selectionStyle="none" indentationWidth="10" reuseIdentifier="RootAppCell" id="PDl-Cx-SrR" customClass="RootAppCell" customModule="Assignment_5">
<rect key="frame" x="0.0" y="28" width="343" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" preservesSuperviewLayoutMargins="YES" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="PDl-Cx-SrR" id="EHS-uv-XgI" customClass="RootAppCell" customModule="Assignment_5">
<rect key="frame" x="0.0" y="0.0" width="343" height="43.5"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<switch opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" contentHorizontalAlignment="center" contentVerticalAlignment="center" on="YES" translatesAutoresizingMaskIntoConstraints="NO" id="uDJ-B5-x3A">
<rect key="frame" x="277" y="6" width="51" height="31"/>
</switch>
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="App Name" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="fWL-xO-z8g">
<rect key="frame" x="18" y="11" width="81" height="21"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
</subviews>
<constraints>
<constraint firstItem="fWL-xO-z8g" firstAttribute="centerY" secondItem="EHS-uv-XgI" secondAttribute="centerY" id="G84-Ys-Q8G"/>
<constraint firstItem="fWL-xO-z8g" firstAttribute="leading" secondItem="EHS-uv-XgI" secondAttribute="leadingMargin" constant="3" id="JrD-j0-SxV"/>
<constraint firstItem="uDJ-B5-x3A" firstAttribute="centerY" secondItem="EHS-uv-XgI" secondAttribute="centerY" id="Q5Q-sy-Qh7"/>
<constraint firstAttribute="trailingMargin" secondItem="uDJ-B5-x3A" secondAttribute="trailing" constant="2" id="bMt-16-diy"/>
<constraint firstItem="uDJ-B5-x3A" firstAttribute="leading" relation="greaterThanOrEqual" secondItem="fWL-xO-z8g" secondAttribute="trailing" id="he7-G6-aBc"/>
</constraints>
</tableViewCellContentView>

最佳答案

如果您不清楚哪些约束存在冲突,请在加载屏幕时查看控制台输出,您应该能够看到与此类似的内容

(
"<NSLayoutConstraint:0x6199cd0 UIButton:0x7fbbf90.width == 0 (active)>",
"<NSLayoutConstraint:0x6998ec0 H:|-(15)-[UILabel:0x6ce60] (active, names: '|':UIButton:0x7fbbf90 )>",
"<NSLayoutConstraint:0x6199000 H:[UILabel:0x6ce60]-(15)-| (active, names: '|':UIButton:0x7fbbf90 )>"
)

为了进一步提供帮助,您可以使用此网页粘贴该部分,它至少会告诉您哪些约束在您的代码中存在冲突。

https://www.wtfautolayout.com/

表格 View 单元格可能会很棘手,因为它们会根据您设置的单元格行高等获得额外的约束。

希望这有助于调试

关于swift - TableView 单元格中的约束似乎被忽略了,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51550080/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com