问题
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 ?
回答1:
In your storyboard, you need to make the root view of your UITableViewController
a UITableView
.
回答2:
Try changing your super class to UIViewController or change the controller in your storyboard to TableView Controller
@interface MTViewController : UIViewController, UITableViewDataSource, UITableViewDelegate
@end
回答3:
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:
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. =)
回答5:
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.
回答6:
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
回答7:
make sure the dataSource is set to self.
来源:https://stackoverflow.com/questions/32875298/storyboard-main-but-didnt-get-a-uitableview-when-using-uitableviewcontroller