菜鸟教程小白 发表于 2022-12-12 16:01:03

ios - 正确定义 UITableViewCell 调整大小的约束


                                            <p><p>我目前正面临这个问题,我需要定义一个动态高度 UITableViewCell。</p>

<p> <img src="/image/5yc6f.png" alt="enter image description here"/> </p>

<p>红线对应于可调整大小的 View (将垂直增长),蓝色标签有 3 个约束:两个用于上面的每个直接红色 View(>= 8),一个具有 170 和较低优先级的 superView 。</p>

<p>绿色的对superview有底部约束(5)</p>

<p>当我尝试运行我的代码时,它给了我这个:</p>

<pre><code>Unable to simultaneously satisfy constraints.
Probably at least one of the constraints in the following list is one you don&#39;t want. Try this: (1) look at each constraint and try to figure out which you don&#39;t expect; (2) find the code that added the unwanted constraint or constraints and fix it. (Note: If you&#39;re seeing NSAutoresizingMaskLayoutConstraints that you don&#39;t understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints)
(
&#34;&lt;NSLayoutConstraint:0x19d65bb0 V:&gt;&#34;,
&#34;&lt;NSLayoutConstraint:0x19d667d0 V:&gt;&#34;,
&#34;&lt;NSLayoutConstraint:0x19d5ba70 V:&gt;&#34;,
&#34;&lt;NSLayoutConstraint:0x19d36df0 V:&gt;&#34;,
&#34;&lt;NSLayoutConstraint:0x19d35d30 V:&gt;&#34;,
&#34;&lt;NSLayoutConstraint:0x19e7b310 V:|-(5)-   (Names: &#39;|&#39;:UITableViewCellContentView:0x19d97580 )&gt;&#34;,
&#34;&lt;NSLayoutConstraint:0x17d0b060 V:-(5)-&gt;&#34;,
&#34;&lt;NSLayoutConstraint:0x17d0a480 V:-(8)-&gt;&#34;,
&#34;&lt;NSLayoutConstraint:0x17d0c920 V:-(8)-&gt;&#34;,
&#34;&lt;NSLayoutConstraint:0x17d0a100 V:-(8)-&gt;&#34;,
&#34;&lt;NSLayoutConstraint:0x17d11ad0 V:-(8)-&gt;&#34;,
&#34;&lt;NSLayoutConstraint:0x19e742a0 V:-(8)-&gt;&#34;,
&#34;&lt;NSLayoutConstraint:0x19ed84a0 V:-(8)-&gt;&#34;,
&#34;&lt;NSLayoutConstraint:0x19e76410 V:-(&gt;=8)-&gt;&#34;,
&#34;&lt;NSLayoutConstraint:0x19ed8af0 V:-(8)-&gt;&#34;,
&#34;&lt;NSLayoutConstraint:0x19e7abf0 V:-(8)-&gt;&#34;,
&#34;&lt;NSLayoutConstraint:0x19e83d90 V:-(8)-&gt;&#34;,
&#34;&lt;NSLayoutConstraint:0x19e7b520 V:-(5)-|   (Names: &#39;|&#39;:UITableViewCellContentView:0x19d97580 )&gt;&#34;,
&#34;&lt;NSAutoresizingMaskLayoutConstraint:0x19d46fc0 h=--&amp; v=--&amp; V:&gt;&#34;
)

Will attempt to recover by breaking constraint
&lt;NSLayoutConstraint:0x19d36df0 V:&gt;

Break on objc_exception_throw to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in &lt;UIKit/UIView.h&gt; may also be helpful.
</code></pre>

<p>所以,问题是:
实现这一目标的正确方法是什么???</p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>你是否使用 <code>storyboard</code>,如果是,简单地转到 <code>Editor->Resolve Auto Layout Issues->Clear All Constraints In .... Controller</code> ,然后 <code>Add Missing Constraints In ...... Controller</code></p>

<p>它将帮助您解决打破 View 之间约束的问题</p></p>
                                   
                                                <p style="font-size: 20px;">关于ios - 正确定义 UITableViewCell 调整大小的约束,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/19614241/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/19614241/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - 正确定义 UITableViewCell 调整大小的约束