ios Storyboard“Main”,但在使用 UITableViewController 时没有得到 UITableView

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/32875298/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 07:53:30  来源:igfitidea点击:

Storyboard "Main", but didn't get a UITableView when using UITableViewController

iosxcodeuitableviewxcode-storyboard

提问by Fred Shmed

I have been going through this tutorial, "Option 2: Prototype Cells" I implimented all the steps, but, the following code gives me an error:

我一直在阅读本教程“选项 2:原型单元格”我执行了所有步骤,但是,以下代码给了我一个错误:

@interface MTViewController : UITableViewController

@end

the error message is:

错误信息是:

instantiated view controller with identifier "UIViewController-BYZ-38-t0r" from storyboard "Main", but didn't get a UITableView.'

实例化视图控制器,标识符为“UIViewController-BYZ-38-t0r”,来自故事板“Main”,但没有得到 UITableView。

Here is what I tried - I changed UITableViewControllerto UIViewControllerand the error went away. But, the tableview remains blank. Can you tell me why this is ?

下面是我尝试-我换UITableViewControllerUIViewController和错误走了。但是,tableview 仍然是空白的。你能告诉我这是为什么吗?

回答by Jarrod Smith

In your storyboard, you need to make the root view of your UITableViewControllera UITableView.

在你的故事板,你需要让你的根视图UITableViewController一个UITableView

Interface Builder Table View Controller

界面生成器表视图控制器

Interface Builder Custom Class

接口生成器自定义类

回答by Bob

Try changing your super class to UIViewController or change the controller in your storyboard to TableView Controller

尝试将您的超类更改为 UIViewController 或将故事板中的控制器更改为 TableView 控制器

@interface MTViewController : UIViewController, UITableViewDataSource, UITableViewDelegate

@end

回答by Babatunde Adeyemi

Drag a new instance of Table View Controller into your storyboard, copy the cells you created in your previous controller into the new one.

将 Table View Controller 的一个新实例拖到您的故事板中,将您在之前的控制器中创建的单元格复制到新的控制器中。

This error occurred probably because you used the default UIViewController created by XCode which isn't a UITableViewController.

发生此错误可能是因为您使用了 XCode 创建的默认 UIViewController,它不是 UITableViewController。

回答by RockingDice

I met exactly the same issue as you. You're probably using a UIViewController instead of a UITableViewController in the storyboard.

我遇到了和你完全一样的问题。您可能在故事板中使用 UIViewController 而不是 UITableViewController 。

NOTE: Only subclass a custom UITableViewController in the storyboard is not enough. You'll see the difference: difference between UIViewController and UITableViewController

注意: 仅在情节提要中创建自定义 UITableViewController 的子类是不够的。你会看到区别: UIViewController 和 UITableViewController 的区别

So you have to drag out a UITableViewController from the library, then move all things(cells) to it. Don't forget to check bindings and auto layouts if broken.

所以你必须从库中拖出一个 UITableViewController,然后将所有东西(单元格)移动到它。如果损坏,请不要忘记检查绑定和自动布局。

And of course you cannot move the tableview to the root of UIViewController, it just doesn't work like that. =)

当然,您不能将 tableview 移动到 UIViewController 的根目录,它只是不能那样工作。=)

回答by luky

I've had this problem too. I created originally plain UIViewControllerthen i decided to rather use UITableViewController. Problem is that i forgot to set storyboard ID on new controller, and change it to something else on the old controller, otherwise you will instantiate the old controller from storyboard and this problem will occur.

我也遇到过这个问题。我最初创建的是普通的,UIViewController然后我决定宁愿使用UITableViewController. 问题是我忘记在新控制器上设置故事板 ID,并将其更改为旧控制器上的其他内容,否则您将从故事板实例化旧控制器,就会出现此问题。

回答by iOS

Actually you are using UIViewController not UITableViewController. Delete your default view controller and drag new TableViewController in your storyboard. Because your ViewController not having TableView, but it's trying to load cells.

实际上您使用的是 UIViewController 而不是 UITableViewController。删除您的默认视图控制器并在故事板中拖动新的 TableViewController。因为您的 ViewController 没有 TableView,但它正在尝试加载单元格。

Simple solution is : Delete ViewController and add TableViewController

简单的解决方案是:删除 ViewController 并添加 TableViewController

Then you have to change its class name to MTViewControlleror Your Class Name

然后您必须将其类名更改为MTViewController您的类名

回答by Areej Mohmmad

In the storyboard just change the class of your ViewController to your new class name which here is MTViewController- image of steps

在故事板中,只需将 ViewController 的类更改为您的新类名,这里是MTViewController-步骤图像

回答by Gontse Ranoto

make sure the dataSource is set to self.

确保 dataSource 设置为 self。