Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.'

like image 941
coding22 Avatar asked Dec 01 '22 13:12

coding22


1 Answers

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).

like image 158
David Liu Avatar answered Dec 07 '22 01:12

David Liu