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:
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.
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.
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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With