菜鸟教程小白 发表于 2022-12-11 18:01:43

ios - Tableview 的 contentView 小于 tableview 框架和单元格


                                            <p><p>我正在使用以下代码以编程方式创建一个 Tableview:</p>

<pre><code> override func viewDidLayoutSubviews() {
    //@begin store selection - settings
    self.tbStores = UITableView(frame: CGRect(x: 15, y: 60, width: UIScreen.main.bounds.size.width - 30, height: 150))
    self.tbStores.register(UITableViewCell.self, forCellReuseIdentifier: &#34;Cell&#34;)
    tbStores.backgroundColor = UIColor.white
    tbStores.delegate = self
    tbStores.dataSource = self
    tbStores.allowsSelection = true;
    tbStores.translatesAutoresizingMaskIntoConstraints = true
}
</code></pre>

<p>并添加以编程方式创建的 ViewAutoComplete</p>

<pre><code>if (viewAutoComplete == nil) {
            self.viewAutoComplete = UIView(frame: CGRect(x: 0, y: 0, width: UIScreen.main.bounds.size.width, height: UIScreen.main.bounds.size.height))
            viewAutoComplete.backgroundColor = UIColor(red: 32 / 255.0, green: 48 / 255.0, blue: 90 / 255.0, alpha: 1)
            viewAutoComplete.alpha = 1
            viewAutoComplete.translatesAutoresizingMaskIntoConstraints = true
            self.viewAutoComplete.tag = 123
    self.view!.addSubview(viewAutoComplete)
            viewAutoComplete.addSubview(tbStores)
}
</code></pre>

<p>问题是 contentView 比 cell 和 tableview 小,如下图所示</p>

<p> <a href="/image/y9Fub.png" rel="noreferrer noopener nofollow"><img src="/image/y9Fub.png" alt="enter image description here"/></a> </p>

<p> <a href="/image/svYBc.png" rel="noreferrer noopener nofollow"><img src="/image/svYBc.png" alt="enter image description here"/></a> </p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>我解决了我的问题</p>

<p> <a href="https://stackoverflow.com/questions/25770119/ios-8-uitableview-separator-inset-0-not-working" rel="noreferrer noopener nofollow">iOS 8 UITableView separator inset 0 not working</a>关于分隔符插入的说明</p>

<p>我刚刚将以下代码添加到我的 <em>viewDidLayoutSubviews</em></p>

<pre><code>tbStores.cellLayoutMarginsFollowReadableWidth = false;
</code></pre></p>
                                   
                                                <p style="font-size: 20px;">关于ios - Tableview 的 contentView 小于 tableview 框架和单元格,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/40530353/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/40530353/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - Tableview 的 contentView 小于 tableview 框架和单元格