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:
I had this issue with Swift 2, Xcode 7.2, I changed a
View Controller
I dragged to myStoryboard
to a customUITableViewController
class, I then dragged aTable View
onto theView Controller
. I didn't realize I placed it as a child of theView
that was part of the originalView Controller
I dragged onto theStoryboard
.I simply deleted the
View
and added the Table View again as the first child of the Super View.SWIFT 2 UPDATE
I tried @Viralsavaj's answer but it didn't work for me until I "hooked up" the tableView as an outlet from the storyboard in the ViewController.
like this:
@IBOutlet weak var tableView: UITableView!
Also add this to your class as @Viralsavaj mentioned:
I used specifically this link help as well: How to reference tableView from a view controller during a segue
Just drag your tableView into the ViewController and make it an outlet. Then you can reference its properties such as
self.tableView.reloadData()
.This property as well as others that referenced the
tableView
were giving me errors until I added the tableView as a referencing outlet.Hope this helps those in the future.
I have face same issue once upon time, and So stupid mistake it was, I have subclass the
UITableViewController
, where I have addedUITableView
inUIViewController
From your storyboard Image, it may be solved if you use
UIViewController
instead ofUITableViewController
, Just try that way can solve your issue,like