菜鸟教程小白 发表于 2022-12-11 18:38:58

ios - 连接到自定义类时单元格消失


                                            <p><p>我在 UITabBarController 的 UINavigationController 中有一个静态单元格 UITableViewController。 </p>

<p>当我为 UITableViewController 创建一个自定义类并设置它时,UITableView 中的所有单元格在构建后都会消失。我可以在设计器中看到它们,但在模拟器或设备中都看不到。 </p>

<p>我是 iOS 开发新手,如果我犯了明显的错误,请原谅。</p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>致所有有同样奋斗的人。在 UINavigationController 中是否有 UITableViewController 并不重要,创建自定义类后,如果有静态单元格,则应注释或删除以下方法:</p>

<pre><code>override func numberOfSections(in tableView: UITableView) -&gt; Int {
    // #warning Incomplete implementation, return the number of sections
    return 0
}

override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -&gt; Int {
    // #warning Incomplete implementation, return the number of rows
    return 0
}

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -&gt; UITableViewCell {
    let cell = tableView.dequeueReusableCell(withIdentifier: &#34;reuseIdentifier&#34;, for: indexPath)

    // Configure the cell...

    return cell
}
</code></pre></p>
                                   
                                                <p style="font-size: 20px;">关于ios - 连接到自定义类时单元格消失,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/46144006/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/46144006/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - 连接到自定义类时单元格消失