我正在尝试创建一个包含3个单元格的表的应用程序

我想扩展UITableViewController而不是UIViewController,所以我想出了这个

//
//  TodoListTableViewController.swift
//  ListHue
//
//  Copyright © 2018 LR Web Design. All rights reserved.
//

import UIKit

class TodoListTableViewController: UITableViewController {

    let items = ["Find Mike", "Buy Eggos", "Kill Demogorgon"]

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

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

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

        let cell = tableView.dequeueReusableCell(withIdentifier: "ToDoItemCell", for: indexPath)

        cell.textLabel?.text = items[indexPath.row]

        return cell
    }

}

启动我的应用程序时,我一直收到此错误
2018-08-01 09:26:53.151150-0400 ListHue[4673:207209] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-[UITableViewController loadView] loaded the "r5i-1Z-XpF-view-oGI-0m-9XK" nib but didn't get a UITableView.'
身份选项卡
ios - UITableViewController loadView加载了“xxx-view-xxx” Nib ,但没有获得UITableView-LMLPHP

连接选项卡

ios - UITableViewController loadView加载了“xxx-view-xxx” Nib ,但没有获得UITableView-LMLPHP

这是我整个情况的屏幕截图

ios - UITableViewController loadView加载了“xxx-view-xxx” Nib ,但没有获得UITableView-LMLPHP

如何进一步调试呢?

最佳答案

问题是您将表拖动到UIViewController实例,但是必须从对象库中拖动UITableViewController

tableViewController的根视图应为UITableView,而不是UIView之类的UIViewController
ios - UITableViewController loadView加载了“xxx-view-xxx” Nib ,但没有获得UITableView-LMLPHP

08-27 19:07
查看更多