[英]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. 我在viewController中有这个按钮,当我按下它时,它应该转到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', 由于未捕获的异常'NSInternalInconsistencyException'而终止应用,
reason: '-[UITableViewController loadView] instantiated view controller with identifier "UIViewController-iLh-Fe-Ezq" from storyboard "Main", but didn't get a UITableView.' 原因:' - [UITableViewController loadView]从故事板“Main”实例化了标识符为“UIViewController-iLh-Fe-Ezq”的视图控制器,但没有得到UITableView。
When I got this error, I had initially used the boilerplate code for the class UITableViewController , but the actual view controller was a UIViewController . 当我收到此错误时,我最初使用了类 UITableViewController的样板代码,但实际的视图控制器是一个UIViewController 。
Original code (resulting in the error) : 原始代码(导致错误) :
Note that this is connected to a UIViewController in Storyboard. 请注意,这是连接到Storyboard中的UIViewController 。
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). 还要记住在视图控制器中为您的UITableView引用IBOutlet,并设置委托和数据源(在Storyboard中,您可以从UITableView按Ctrl + Drag拖动到视图控制器顶部的黄色圆圈,然后单击dataSource。重复此操作代表也是)。
我让它工作....我使用没有视图控制器的表视图控制器并嵌入了导航控制器。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.