gpt4 book ai didi

ios - 如何修复 "nib but didn' t get a UITableView"error?

转载 作者:搜寻专家 更新时间:2023-10-30 22:02:08 25 4
gpt4 key购买 nike

为什么会出现这个错误?

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
}

我的 Storyboard是这样的:

storyboard

最佳答案

我曾经遇到过同样的问题,这是一个愚蠢的错误,我有 UITableViewController 的子类,我在 UIViewController< 中添加了 UITableView/

从你的 Storyboard图片中,如果你使用 UIViewController 而不是 UITableViewController 可能会解决,只需尝试这种方式就可以解决你的问题,比如

class FriendListTableViewController: UIViewController, UITableViewDataSource, UITableViewDelegate 

关于ios - 如何修复 "nib but didn' t get a UITableView"error?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30028129/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com