如何修复"nib但没有得到UITableView"错误?

Ega*_*tra 6 iphone uitableview uiview ios swift

为什么我会收到此错误?

由于未捕获的异常'NSInternalInconsistencyException'终止应用程序,原因:' - [UITableViewController loadView]加载了"pB1-re-lu8-view-o7U-YG-E7m"笔尖,但没有得到UITableView.

这是我的代码:

class FriendListTableViewController: UITableViewController{


var objects = NSMutableArray()
var dataArray = [["firstName":"Debasis","lastName":"Das"],["firstName":"John","lastName":"Doe"],["firstName":"Jane","lastName":"Doe"],["firstName":"Mary","lastName":"Jane"]]

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

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}

// MARK: - Table View

 override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
    return 1
}

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

 override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {

    let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as! UITableViewCell
    let object = dataArray[indexPath.row] as NSDictionary
    (cell.contentView.viewWithTag(10) as! UILabel).text = object["firstName"] as? String
    (cell.contentView.viewWithTag(11) as! UILabel).text = object["lastName"] as? String
    return cell
}

 override func tableView(tableView: UITableView, canEditRowAtIndexPath indexPath: NSIndexPath) -> Bool {
    // Return false if you do not want the specified item to be editable.
    return false
}
Run Code Online (Sandbox Code Playgroud)

我的故事板是这样的:

故事板

Vir*_*vaj 19

我曾经一次面对同样的问题,所以这是一个愚蠢的错误,我已经将UITableViewController其加入UITableView了子类中UIViewController

从你的故事板Image,如果你使用UIViewController而不是,它可能会被解决UITableViewController,只是尝试这种方式可以解决你的问题,如

class FriendListTableViewController: UIViewController, UITableViewDataSource, UITableViewDelegate 
Run Code Online (Sandbox Code Playgroud)