如何修复“nib但没有得到UITableView”错误? [英] How to fix "nib but didn't get a UITableView" error?

查看:159
本文介绍了如何修复“nib但没有得到UITableView”错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么我收到此错误?

Why I get this error?


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

Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-[UITableViewController loadView] loaded the "pB1-re-lu8-view-o7U-YG-E7m" nib but didn't get a UITableView.'



<这是我的代码:

here is my code:

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
}

我的故事板是这样的:

推荐答案

我曾经一次面对同样的问题,所以这是一个愚蠢的错误,我有 UITableViewController 的子类,我在哪里在 UIViewController中添加 UITableView

I have face same issue once upon time, and So stupid mistake it was, I have subclass the UITableViewController, where I have added UITableView in UIViewController

从故事板中添加图片,如果你使用 UIViewController 而不是 UITableViewController ,它可能会被解决,试试这种方式可以解决你的问题,比如

From your storyboard Image, it may be solved if you use UIViewController instead of UITableViewController, Just try that way can solve your issue,like

class FriendListTableViewController: UIViewController, UITableViewDataSource, UITableViewDelegate 

这篇关于如何修复“nib但没有得到UITableView”错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆