菜鸟教程小白 发表于 2022-12-12 15:32:35

ios - UITableViewCell 行高缩小到默认 44 像素(iOS 8)


                                            <p><p>我有一个包含不同高度单元格的 tableView。我依靠 iOS 8s 自动调整大小功能来计算高度。当 View 加载时,一切看起来都很好并且按计划进行。在某些时候需要删除一个单元格。在删除动画之后,其余的单元格将动画到 44 像素的高度,原因不明。单元格中的所有 View 都使用自动布局进行布局,因此我对原因一无所知。</p>

<p>由于某些限制,我无法尝试以下操作:</p>

<ul>
<li>重新加载表格 View 或</li>
<li>使用 heightForRowAtIndexPath,因为有几个单元格具有动态高度,并且在调用此委托(delegate)方法时不可用。 </li>
</ul>

<p>最大的问题是为什么?我该如何应对这种行为?</p>

<p>删除的行是:</p>

<pre><code>tableView.deleteRowsAtIndexPaths(, withRowAnimation: UITableViewRowAnimation.Fade)
</code></pre>

<p>动态行具有多行 UILabel 或 UIView。自动布局是通过 IB 完成的</p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>我遗漏了以下几行:</p>

<pre><code>self.tableView.rowHeight = UITableViewAutomaticDimension
self.tableView.estimatedRowHeight = 44.0
</code></pre>

<p>细胞不再缩小。</p></p>
                                   
                                                <p style="font-size: 20px;">关于ios - UITableViewCell 行高缩小到默认 44 像素(iOS 8),我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/31020478/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/31020478/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - UITableViewCell 行高缩小到默认 44 像素(iOS 8)