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.
Related
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)
}
This has been asked before but as you can see from the picture a simple control+drag from the story board to the controller doesn't work. I made a new Cocoa Class subclass of UIViewController. After I try to hook up my Map View to it and it simply does not respond.
You have most likely not set your View Controller's class to your newly created class.
You can do this by going to your View Controller's Identity Inspector and changing the class from UIViewController to MapViewController.
You'll then be able to connect UI elements.
You might have forgotten to set the class of the view controller you have in the storyboard. Make sure the class is set to "MapViewController"
Here is where you set it :
Setting the Class of a VC in Storyboard
It's your own issue.
1) Storyboard on left side
2) class(ViewController) should be automatic in right side.
See image below:
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
}
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 .
I am having issues making UILabels and IBAction buttons in custom classes. Xcode seems to not want me to do it. They way I'm trying to do it is through interface builder (storyboard). I have no issue clicking and dragging to make IBOutlets and IBActions using the main View Controller but when I click and drag over to connect them in a custom class it does nothing. Am I only able to make these in the View Controller? I've attached a pic of me trying to drag over to connect my button in the custom class and you can see that nothing pops up. So basically, Are labels, buttons, text fields etc, for the View Controller class only? Thanks for any feedback.
Within interface builder, you will need to make sure your view controller is using your custom class by opening utilities view on the RHS of the IB, selecting the third icon along (please see picture below) and enter your custom class name in the space provided.
Your custom class will need to be a subclass of UIViewController though, like the picture below, not an NSObject for example.
I'm referring to this line within your .h file ...
#interface MyCustomClassViewController : UIViewController
Your custom class needs to match the UI object you are connecting it with. For example if you had UIView object, your custom class would need to be a subclass of UIView, a UINavigationViewController object, a subclass of UINavigationController etc etc.
I hope this helps.
Select your view controller in the stoyboard and go to the identity inspector, make sure the name there is your custom class name.