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

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

问题描述

为什么会出现这个错误?

Why I get this error?

由于未捕获的异常而终止应用'NSInternalInconsistencyException',原因:'-[UITableViewControllerloadView] 加载了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.'

这是我的代码:

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

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 

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

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