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

8

27

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 ?

Lutes answered 30/9, 2015 at 20:44 Comment(1)
What do you mean blank? When you add a View Controller to your storyboard it's vanilla. You have to add the elements to it.Saltzman
C
50

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

Interface Builder Table View Controller

Interface Builder Custom Class

Calabash answered 21/3, 2016 at 0:47 Comment(0)
S
19

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

@interface MTViewController : UIViewController, UITableViewDataSource, UITableViewDelegate

@end
Saltzman answered 1/10, 2015 at 23:35 Comment(0)
C
8

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.

Conceptionconceptual answered 18/10, 2015 at 16:10 Comment(2)
very subtle problem and obvious solution (assuming you appreciate the problem). now, why are my cell properties coming back NIL?Matelot
this is wierd but it's true. Had the same problem, solved like you describedChristcrossrow
T
8

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. =)

Tideway answered 25/3, 2018 at 13:5 Comment(0)
C
5

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.

Simple solution is : Delete ViewController and add TableViewController

Then you have to change its class name to MTViewController or Your Class Name

Cymbal answered 11/9, 2018 at 8:11 Comment(0)
H
3

I've had this problem too. I created originally plain UIViewController then 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.

Humdrum answered 15/8, 2017 at 11:53 Comment(0)
I
2

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

Implausibility answered 10/3, 2020 at 11:35 Comment(0)
B
0

make sure the dataSource is set to self.

Brout answered 18/6, 2018 at 11:8 Comment(2)
Can you be more precise, or even share some code that helps to understand your answer?Axseed
Use comment for this kind of info.Speculative

© 2022 - 2024 — McMap. All rights reserved.