菜鸟教程小白 发表于 2022-12-13 02:33:28

ios - 为主 TableView 的行设置动态高度,它有另一个从 TableView ?


                                            <p><p>我想根据内部从 TableView 的高度动态设置主 TableView 的行高。实现这一目标的最佳方法是什么?
<a href="/image/nosoM.png" rel="noreferrer noopener nofollow"><img src="/image/nosoM.png" alt="enter image description here"/></a> </p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>尝试使用<code>UITableViewAutomaticDimension</code>动态设置外部tableview的行高。 </p>

<pre><code>override func viewDidLoad() {
    super.viewDidLoad()

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

<p><strong>或</strong></p>

<pre><code>func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -&gt; CGFloat {
    return UITableViewAutomaticDimension
}
</code></pre>

<p>通过上面的代码,外部tableview的行高将根据内部tableview的高度动态设置。</p></p>
                                   
                                                <p style="font-size: 20px;">关于ios - 为主 TableView 的行设置动态高度,它有另一个从 TableView ?,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/45837468/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/45837468/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - 为主 TableView 的行设置动态高度,它有另一个从 TableView ?