OGeek|极客世界-中国程序员成长平台

标题: ios - 连接到自定义类时单元格消失 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-11 18:38
标题: ios - 连接到自定义类时单元格消失

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

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

我是 iOS 开发新手,如果我犯了明显的错误,请原谅。



Best Answer-推荐答案


致所有有同样奋斗的人。在 UINavigationController 中是否有 UITableViewController 并不重要,创建自定义类后,如果有静态单元格,则应注释或删除以下方法:

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

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

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCell(withIdentifier: "reuseIdentifier", for: indexPath)

    // Configure the cell...

    return cell
}

关于ios - 连接到自定义类时单元格消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46144006/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4