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

本秂侑毒 提交于 2020-01-01 06:26:40

问题


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


回答1:


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




回答2:


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



来源:https://stackoverflow.com/questions/33181748/why-do-i-keep-getting-this-error-when-going-from-viewcontroller-to-tableviewcont

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!