Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何调试未显示行的UITableView?_Ios_Swift_Uitableview_Tableview - Fatal编程技术网

Ios 如何调试未显示行的UITableView?

Ios 如何调试未显示行的UITableView?,ios,swift,uitableview,tableview,Ios,Swift,Uitableview,Tableview,我有一个视图控制器 class PlacesVC: UITableViewController { override func viewDidLoad() { super.viewDidLoad() } // MARK: - Table view data source override func numberOfSections(in tableView: UITableView) -> Int { return 1

我有一个视图控制器

class PlacesVC: UITableViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
    }

    // MARK: - Table view data source
    override func numberOfSections(in tableView: UITableView) -> Int {
        return 1
    }

    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return 4
    }


    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

        let cell = UITableViewCell(style: .default, reuseIdentifier: "Cell")
        cell.textLabel?.text = "Row \(indexPath.row)"

        return cell
    }

    override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        performSegue(withIdentifier: "toMap", sender: kill)
    }
}
我还将单元格的id设置为cell

当我构建并运行应用程序时,我总是得到一张空表

我希望得到这样的4排

如何调试为什么我的行没有显示?

您可以试试

func tableView(_ tableView: UITableView, 
     heightForRowAt indexPath: IndexPath) -> CGFloat {

   return 60
}
如果你想要动态的

tableView.estimatedRowHeight = 60 
tableView.rowHeight = UITableViewAutomaticDimension

首先,确保已将tableView的委托和数据源属性设置为该viewController的实例,否则将不会调用这些方法。如果您的ViewController继承自TableViewController,则可以跳过此步骤

第二件事,您正在为每一行启动一个新的cell实例,而不是重用它。 因此,替换这一行:

    let cell = UITableViewCell(style: .default, reuseIdentifier: "Cell")
与:

第三件事:确保从IB设置了正确的类


最后一件事:将样式从“自定义”更改为“基本”,以获得默认的文本标签。

您需要在故事板上的ViewController的“标识检查器”部分中设置类

检查是否已在代码中添加tableView委托和数据源

如果要使用自定义类来创建新的表格单元格,请注册一个类。在viewDidLoad中,类似于:   tableView.register{your cell class},forCellReuseIdentifier:identifier

通过初始化单元格对象

tableView.dequeueReusableCellWithIdentifier:,forIndexPath:

如果您没有为您的计算单元使用任何类,那么您不需要注册您的类。 您只需通过以下方式初始化单元对象:


tableView.dequeueReusableCellWithIdentifier:

UITableViewCellstyle:。默认,reuseIdentifier:Cell->tableView.dequeueReusableCellWithIdentifier:Cell,for:InExpath我可以在情节提要中看到4关于默认UITableViewController和您共享的代码。你能分享更多细节吗?@PrashantTukadiya,不,我仍然看到空的。还有,我现在买的有什么问题?这是过时的语法吗?@EmreÖnder。我能提供什么?我还不知道如何调试这个东西。我是iOS新手。实现heightForRowAt??实际上,他不需要设置这些属性,因为它已经是一个UITableViewController。也许故事板有一个普通的UIViewController,但类是一个UITableViewController?很抱歉,伙计们,我忘记给我的tableVC分配一个类了。通过这样做:,现在它工作了;如果要检查委托是否已连接,请向现有方法添加断点,如果它们被命中,则会设置委托。我敢打赌他们不会被击中…问题是他们缺了班!如果没有heightForRowAt函数,我仍然可以看到行。只是让你知道;是的,但是当系统没有找到满足当前设置的Rowat高度或动态单元格约束时,系统会设置这些约束以避免崩溃。代码中已经存在Legate和dataSource方法,并且不需要将其作为PlacesVC委托&dataSource从UITableViewControllerCustom类派生,不需要注册在本例中,as OP已将它们添加到情节提要中,并将单元的类类型设置为自定义类。它是通过故事板自动注册的。在答案的最后一部分,tableView.dequeueReusableCellWithIdentifier:如果有人隐式或显式注册任何单元格,将如何返回任何单元格?不要将UITableViewCell与UICollectionViewCell混淆。考虑为UITababVIEW阅读DeBealeReUabLeCeleAppEdoc。抱歉,它是UITable VIEW单元类
    let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath)