iewController到TableViewControlle

iewController到TableViewControlle

本文介绍了从ViewController到TableViewController时,为什么总是出现此错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的viewController中有这个按钮,当我按下它时,它应该转到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!

推荐答案

出现此错误时,我最初使用 class UITableViewController 的样板代码,但是实际视图控制器 UIViewController .

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

原始代码(导致错误):

请注意,这已连接到Storyboard中的 UIViewController .

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
}

工作代码(消除错误):

class MainViewController: UIViewController {
//insert code here
//you also must *remove the override keywords* for
// some of the included functions or you will get errors
}

还请记住在视图控制器中为UITableView引用IBOutlet,并设置委托和数据源(在Storyboard中,按住Ctrl + Drag从UITableView到视图控制器顶部的黄色圆圈,然后点击dataSource.同样对代理重复此操作.)

这篇关于从ViewController到TableViewController时,为什么总是出现此错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 19:55