Unable to add an action to my controller from storyboard iOS - ios

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:

Related

"Launch screens may not set custom class names"

I'm trying to set the initial view controller to a custom class. In previous versions this worked but for some reason I cannot do it now.
I have a UIViewController class (IntroVC). In the storyboard I created a new View Controller object and set it's class (Identity Inspector -> Custom Class -> Class) to IntroVC. IntroVC is a .swift file with functions viewDidLoad() and didReceiveMemoryWarning() of class IntroVC: UIViewController.
Here are screenshots of XCode
Error
IntroVC
Storyboard
Anyone know how to solve this? What's up with this version of XCode?
I made a really simple mistake.
This error occurred when a custom class was set in LaunchScreen.storyboard. I should have set my custom IntroVC class in Main.storyboard.
Setting the initial VC class in LaunchScreen.storyboard to UIViewController and the initial VC class in Main.storyboard to IntroVC fixed the problem.
XCode 7.0.1 is fine. The mistake is my own.
Go through your View Controllers in Main.storyboard and make sure you don't have one that is both set to a custom class:
and has "Is Initial View Controller" checked:
You can only do one or the other. Somehow I had "Is Initial View Controller" still checked by mistake, and it took me a while to hunt that down!
Check if you're changing the "LaunchScreen.xib" file view class in the identity inspector. It should be a standard UIView, maybe you set it to a view controller class by accident.
This occurs due to if you are set the class name for the LaunchScreen.Storyboard file in the Identity Inspector. Just remove the class name and it will work fine.

Can't set view outlet in xib

I have a xib file that includes a view controller but I have the same problem as this link: problem
In this answer they can easily set outlet because view has a circle that is clickable.But in my case the view outlet is not even clickable.So I can't set the outlet.What to do now?
The correct way to use initWithNibName:: is to have a "View" IB document where you have the desired VC view outlet as a root element. You need to set the "File's Owner" "Class" to your UIViewController subclass and connect it's view outlet:
Also, don't present modal VC from self at viewDidLoad: at the time of this method execution the VC is often not yet presented itself, viewDidAppear: is more fitting for such tests.
I had this same problem, but neither this nor any other solutions seemed to work - what I wound up doing was setting the custom class to UIViewController, linking the view as described in the question link, and then changing the class back to the actual custom class name I had intended. The link stayed and everything worked from that point on.

Unable to make outlets

I'm not able to create an outlet on the view controller.
I started out with the single view application template, and added another view controller to my storyboard. Now, when I try to create an outlet from the second view controller to the file, Xcode doesn't allow me to make it.
What could be the problem?
When you add a View Controller on a story board you have to change it's class to the View Controller you want it to be controlled by, you can do it by opening the Identity Inspector tab in the Utilities panel (option+command+3) and type or find the class name of the View Controller you want, after doing this, you can play with it's outlets, check out the screenshot:
EDIT: Forgot to mention, you have to have selected the View Controller you want to change the class for in the left list.

trying to hook up UILabels and IBActions in a custom class (Xcode 5)

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.

Can't set custom class name

I can't seem to be able to set the identity of my view to GraphViewController in Xcode 4.2.
I dragged a regular UIView in storyboard on a UIScrollView.
I create a new file called GraphViewController extending UIViewController (.h and .m) but when I click on my view in storyboard and try to set the custom class name (its identity) to GraphViewController, it doesn't set it. It doesn't even show it in the dropdown list.
Am I missing something here a connection or something?
You can set any class inherited from UIView to a UIView instance.
But you have created a UIViewController subclass, not a UIView subclass.
You can assign your custom class to the controller, not to the view.
In case anyone ever makes the dumb mistake I just did... ensure you have created an appropriate storyboard for either iOS or OS X. Adding the wrong one to your project will certainly cause issues like this.
My solution was making sure I was clicking on the controller's top tool bar, and not the "screen" UI frame. If you select the frame or anything in it, your Identity Inspector will be looking at the View, or other elements in the storyboard, instead of the controller itself.

Resources