Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fix "nib but didn't get a UITableView" error?

Why I get this error?

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
}

my storyboard is like this:

storyboard

like image 608
Ega Setya Putra Avatar asked May 04 '15 10:05

Ega Setya Putra


People also ask

How do I populate UITableView?

There are two main base ways to populate a tableview. The more popular is through Interface Building, using a prototype cell UI object. The other is strictly through code when you don't need a prototype cell from Interface Builder.

What is UITableView?

UITableView manages the basic appearance of the table, but your app provides the cells ( UITableViewCell objects) that display the actual content. The standard cell configurations display a simple combination of text and images, but you can define custom cells that display any content you want.


2 Answers

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

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 
like image 168
Viral Savaj Avatar answered Sep 24 '22 10:09

Viral Savaj


I had this issue with Swift 2, Xcode 7.2, I changed a View Controller I dragged to my Storyboard to a custom UITableViewController class, I then dragged a Table View onto the View Controller. I didn't realize I placed it as a child of the View that was part of the original View Controller I dragged onto the Storyboard.

I simply deleted the View and added the Table View again as the first child of the Super View.

like image 42
Brian Ogden Avatar answered Sep 22 '22 10:09

Brian Ogden