简体   繁体   English

从ViewController到TableViewController时,为什么一直出现此错误?

[英]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.

相关问题 为什么在加载TableViewcontroller时出现此错误 - Why am I getting this error when loading my TableViewcontroller 从其他视图控制器调用时,tableviewController无法正常工作 - tableviewcontroller not working when called from other viewcontroller 滚动TableViewController时出现错误 - Getting Error when scrolling the tableviewcontroller 从ViewController到TableViewController - From ViewController to TableViewController 无法在目标C中从ViewController到tableViewController获取XML解析数据? - XML Parsing data not getting from viewController to tableViewController in objective c? 当我尝试在Swift中对动作进行排序时,为什么仍会收到此错误? - Why do I keep getting this error when I try to sequence my actions in Swift? 如何将TableViewController连接到我的主ViewController? - How do I connect a TableViewController to my main ViewController? 应用重新运行时,如何保存ViewController中的数据并将其加载到TableViewController中? - How to save data from ViewController and Load it to TableViewController when app rerun? 我如何将数据从SlideTableTableViewController传递到ViewController中嵌入的TableView - How i pass Data from SlideOut TableViewController to TableView embedded in ViewController 如何从ViewController变为TableViewController - How to go from a viewcontroller to a tableviewcontroller
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM