Can't find NewViewController subclass in Storyboard view - ios

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.

Related

Cannot connect View Controller to Swift file

I created a second view controller in the storyboard. I also created a new Swift-file with File - New - Cocoa..... Now I want to associate that Swift-file with the second view controller. So I highlight the second view controller, and click Show Identity Inspector. In Custom Class in the Class field I normally would add the Swift-file in order to create i.e. outlets. However, I cannot find the newly created Swift-file in there.
Thats the code from the new Swift-file
import UIKit
class EditImageViewController: NSObject {
}
Why is that?
In your newly created Swift file. You need to declare a class which inherits from UIViewController.
Like:
class SomeViewController: UIViewController {
}
Then you will be able to connect IBOutlets and IBActions to this class.
If you are still having issues after your class inherits from UIViewController check the file inspector and ensure that the {your app name} target is checked (so that the file belongs to the correct module)

Accessing UITabBarController variable in Swift

I want to be able to subclass UITabBarController so I can add a variable and access it from the view controllers that it manages. Is this possible or should I move the var to a separate class/ app delegate? Thanks!
Yes definitely possible. For example, I'll use the class name CustomTabBarController so create a new Swift file using the template iOS / Cocoa Touch Class named CustomTabBarController.swift and in the new file dialog have it subclass UITabBarController.
You now have your custom class that inherits UITabBarController. You can add your properties and methods.
Now in your Storyboard add a UITabBarController (or select your existing one). In the inspector pane, click the Identity tab and set the custom class to CustomTabBarController.
Now to access your property or method in a ViewController that's in your CustomTabBarController, you could use something like this within that ViewController:
if let customTabBarController = self.tabBarController as? CustomTabBarController {
print(customTabBarController.variableName)
}

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

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.

custom class not getting assigned to view controller

I have following view controllers in my storyboard
I have created two custom class, which are RegisterViewController.swift and SignInViewController.swift, when I select my RegisterViewController in storyboard, I can see RegisterViewController.swift being assigned to my registerviewController, but when I create new custom class called SignInViewController.swift and when I try to assign it to the SignInview, it is not getting assigned however it is appearing in my custom class dropdown, just to make sure, if I select assistant editor, I see the RegisterViewController.swift code but it should be showing SignInViewController.swift code. What I am missing here?
This how my identity inspector looks when I select SignInViewController
This is my signinviewcontroller.swift
import UIKit
class SignInViewController: UIViewController {
//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.

Resources