coding22
coding22

Reputation: 689

Why do I keep getting this error when going from ViewController to TableViewController?

I have this button in my viewController and when I press on it, it should go to the TableViewController. When I do this the app crashes and prints this error in the console. Can someone tell me what Im doing wrong? Thank you!

Terminating app due to uncaught exception 'NSInternalInconsistencyException',
reason: '-[UITableViewController loadView] instantiated view controller with identifier "UIViewController-iLh-Fe-Ezq" from storyboard "Main", but didn't get a UITableView.'

Upvotes: 4

Views: 6805

Answers (2)

David Liu
David Liu

Reputation: 316

When I got this error, I had initially used the boilerplate code for the class UITableViewController, but the actual view controller was a UIViewController.

Original code (resulting in the error):

Note that this is connected to a UIViewController in Storyboard.

class MainViewController: UITableViewController {
//insert rest of code here 
//note that funcs such as numberOfRowsInSection(_:) will have the override keyword 
}

Working code (removing the error):

class MainViewController: UIViewController {
//insert code here 
//you also must *remove the override keywords* for
// some of the included functions or you will get errors
}

Remember also to reference an IBOutlet for your UITableView in your view controller, and set the delegate and datasource (in Storyboard, you Ctrl+Drag from the UITableView to the yellow circle at the top of the view controller, and click dataSource. Repeat this for the delegate as well).

Upvotes: 17

coding22
coding22

Reputation: 689

I got it to work....I used a table view controller without the view controller and embedded a navigation controller.

Upvotes: 1

Related Questions