Storyboard “Main”, but didn't get a UITableVie

2020-05-22 05:06发布

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

@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.'

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

8条回答
看我几分像从前
2楼-- · 2020-05-22 05:19

make sure the dataSource is set to self.

查看更多
劫难
3楼-- · 2020-05-22 05:22

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

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

查看更多
成全新的幸福
4楼-- · 2020-05-22 05:23

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

Interface Builder Table View Controller

Interface Builder Custom Class

查看更多
神经病院院长
5楼-- · 2020-05-22 05:24

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

@interface MTViewController : UIViewController, UITableViewDataSource, UITableViewDelegate

@end
查看更多
爷的心禁止访问
6楼-- · 2020-05-22 05:28

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

查看更多
SAY GOODBYE
7楼-- · 2020-05-22 05:35

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

NOTE: Only subclass a custom UITableViewController in the storyboard is not enough. You'll see the difference: difference between UIViewController and 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.

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

查看更多
登录 后发表回答