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

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 ?

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

Try changing your super class to UIViewController or change the controller in your storyboard to TableView Controller
#interface MTViewController : UIViewController, UITableViewDataSource, UITableViewDelegate
#end

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.

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

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

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.

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

make sure the dataSource is set to self.

Related

Convert TableViewController to ViewController

I have started with a TableViewController but now I would like to change from a TableViewController to a ViewController in the storyboard. Is there an easy way to do this? I want to avoid creating a new View scene in the storyboard and copying the code over.
You have to delete the current TableViewController and create a new ViewController.
If you will set an TableView inside, you also must set DataSource/Delegate, and conform with the Table Views protocols in the ViewController Class.
You can do that using ContainerView. Take one UIViewController and add a ContainerView inside it. Control drag from the ContainerView to TableViewController and select EmbedIn. This is the only way to keep existing TableViewController, but you need to move your code from TableViewController to ViewController. Do this only if it is necessary to use TableViewController and you have to display a View outside the TableView.
Just start implementing ViewController protocol and remove TableViewController, TableViewControllerDelegate and TableViewControllerDataSource.
Also remove the methods from the TableViewDataSource and that's it.

2 or more UIViewcontroller with the same class crash

I am have multiple view controller in my storyboard with same class called "viewcontroller.swift " and they crash but if I assign operate classes they don't crash how do i fix this?
Simple answer for that is you can not use single ViewController.swift for multiple view controllers in your storyboard. Just create a new class for every new view controller in storyboard.
I tried same ViewController sub class in Obj-C for multiple storyboard view controllers and mentioned storyboard id for each ViewController and it worked fine, no crashes occur. You can try this in Swift as well.

Reuse childs from custom UIVIewController using storyboard

I have a storyboard with a navigation controller that leads to an UIVIewController that I want to reuse. That UIVIewController has a ParentUIViewController that has all the basic functionalities for all the UIVIewControllers that I am reusing.
Currently I am copying and pasting (meh) and then I change the class of the UIViewController to the ChildUIVIewController that I want to use (ChildUIViewController extends ParentUIViewController).
But this sounds like a bad solution. Everytime I want to change the ParentViewController visually I need to update, manually, all other ChildViewControllers.
I have tried to create a xib for the ParentViewController but the xib isn't loaded because I need a xib with the name of the ChildViewController. I have created it and then said the class is the ParentViewController but it crashes in the segue.
EDIT
I have created an example of the status of my problem
https://github.com/tiagoalmeida/storyboardexample
Note that the ParentViewController has a set of logic way more complicated that is not illustrated there. Also note that I am also using a TableView. I hope that this can illustrate the problem.
Keep the logic on the parentViewController and the UI Part on the child UIViewControllers. If you need to create a new UIViewController, you will create a child that will have a corresponding XIB (or get rid of XIBs and create the interface by hand).
Have you considered looping back into the same UIViewController via a "phantom button"?
Have a look at this: UIStoryboard Power Drill, Batteries included
Essentially you can drag a Bar Button Item into the little black bar under the View Controller in Storyboard (the 1 with View Controller, First Responder, and Exit icons; sorry, I don't recall what this is called exactly), then you can control+drag from that button back into the UIViewController for a Push segue. This should create a loop segue in your Storyboard. All you need to do next is give that segue an identifier, programmatically call it from your code using [self performSegueWithIdentifier:], then implement -(void)prepareForSegue: and use [segue destinationViewController] to conditionally set the title and perhaps some flags so you can identify when to use different kinds of fetches (or other code variations) in the same Class code.

Set the subclass for `ECSlidingViewController`

I'm trying to add the ECSlidingViewController in my project, but I'm a novice on iOS and I'm not sure what to do in order to follow the instructions: "Add a UIViewController to your storyboards and set the subclass to ECSlidingViewController"
I've added the UIViewController, but now how do I set the subclass?
I don't use storyboards, but it sounds like you have to set custom class for this controller in identity inspector.
Suppose, you added an UIViewController in StoryBoard named "InitialSlidingViewController".
Then in InitialSlidingViewController.h, you should make the interface declaration as follows.
#interface InitialSlidingViewController : ECSlidingViewController
And please check the demo given by "ECSlidingViewController". You will understand it then.
I think you've got class and subclass the wrong way around.
What you are creating is a class called ECSlidingViewController that is a subclass of UIVIewController.
In you ECSlidingViewController.h you should have the following...
#interface ECSlidingViewController : UIViewController
This means you are defining a class called ECSlidingViewController and it is a subclass of UIViewController.

Can't find NewViewController subclass in Storyboard view

I want to change a TableViewController to a new UIViewController (PlayersViewController) from a UIViewController subclass, so I added two files (.h, .m), and then went back to the Identity Inspector/Custom Class.
Expected to find the PlayersViewController in the pulldown menu in Custom Class but could not find it, so I typed it in and hit "Return", but that didn't work either.
Am I doing something wrong?
Your new class should inherit from UITableViewController, not UIViewController. Only subclasses of the base class are available to select in the custom class field.

Resources