custom class not getting assigned to view controller - ios

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
}

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)
}

How to connect own class to UITabBar element?

I created UITabBarController at storyboard.
Also I have created the separated class.
How I can connect my empty class to UITabBarController, that to make settings of TabBar in section:
- (void)viewDidLoad
{
// Change background TabBar at whole project
// Set border bottom for selected item
}
I tried to set name class in storyboard for TabBar, but it does not allow
First : You create your custom class who is a subclass of UITabBarController
Then : in your nib file
You can set your new custom class to your nib. For example, AFSTVolumeDetailViewHeader in the image below. Don't forget to press enter after you put the name of your class and check if it works by pressing the arrow next to the name of the class.
In your storyboard select your UITabBarController. Then in the right pane select the Identity Inspector. Enter your class name in the Class field.
If the inspector doesn't allow you to enter your custom class make sure that your custom class is a subclass of UITabBarController.

Can't use the drag function in .h when using storyboard with more than one view controller

I can't use the control drag function to hook up a button to action in .h when using storyboard with more than one view controller
Please help me...
Are you sure you've assigned the view controller a custom class? and dragging to that specific class? Each view controller should have its own Obj-c class. To create one:
press cmd + n and create a new Objective-C class and make it a subclass of UITableViewController (or the view controller you used in your Storyboard). after doing so, go to you Storyboard and select the view controller, on the right menu choose "Identity Inspector" and set the custom class name to the name of the class you just created.
Set the class file name for the UIViewController of the storyboard file at the identity inspector .

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