Why am I getting this error when switching from ViewController to TableViewController?

I have this button in my viewController dispatcher, and when I click on it, it should go to the TableViewController. When I do this, the application crashes and prints this error in the console. Can someone tell me what I am doing wrong? Thanks!

Application termination due to the uncaught exception "NSInternalInconsistencyException",
    reason: '- [UITableViewController loadView] - created controller instance identifier "UIViewController-iLh-Fe-Ezq" from the "Main" storyboard, but did not get a UITableView. ''

+4
source share
2 answers

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

Source code (leading to an error) :

Note that this is due to the UIViewController in the storyboard.

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

Work code (error removal) :

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 the IBOutlet for your UITableView in your view controller and set the delegate and data source (in the 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).

+17
source

.... .

+1

Source: https://habr.com/ru/post/1612007/


All Articles