菜鸟教程小白 发表于 2022-12-11 16:45:20

ios - Objective C Table Cell ContentView View 层次结构没有为约束准备


                                            <p><p> <a href="http://i.stack.imgur.com/UjYGN.png" rel="noreferrer noopener nofollow">Storyboard</a> </p>

<p>我添加了一个带有 Storyboard的标签,我在表格中有一个标签(约束顶部:10 左:0 右:0)。根据状态,如果要创建图像并添加约束,我会收到此错误:</p>

<pre><code>2016-06-17 16:02:59.235 Cellin ***
Terminating app due to uncaught exception
&#39;NSInvalidArgumentException&#39;, reason: &#39;*** +: Constraint must contain a first layout item&#39;
</code></pre>

<p>解决了这个缺少 IBOUTLET 的错误;
新错误:</p>

<pre><code>The view hierarchy is not prepared for the constraint: &lt;NSLayoutConstraint:0x7fce22494cf0 V:-(50)-&gt;
    When added to a view, the constraint&#39;s items must be descendants of that view (or the view itself). This will crash if the constraint needs to be resolved before the view hierarchy is assembled. Break on - to debug.
2016-06-17 16:17:14.152 Cellin *** Assertion failure in -[UITableViewCellContentView
</code></pre>

<p>我的表代码</p>

<pre><code>-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    TableCellController *cell = ;
    cell.TLabel.text = ;
    if(true){
      UIImageView *images = [ init];
      ;
      ;
      images.image = ;

      NSLayoutConstraint *TComp = ;

      ;
    }
    return cell;
}
</code></pre></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p><strong>约束必须包含第一个布局项</strong>清楚地表明您在此调用中缺少 <code>firstItem</code>。</p>

<pre><code>NSLayoutConstraint *TComp = ;
</code></pre>

<p>也许您需要检查 <code>cell.TLabel</code> 是否正确加载。缺少 <code>IBOutlet</code> 吗?</p></p>
                                   
                                                <p style="font-size: 20px;">关于ios - Objective C Table Cell ContentViewView 层次结构没有为约束准备,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/37882354/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/37882354/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - Objective C Table Cell ContentView View 层次结构没有为约束准备