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

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 .

Related

I can't connect the IBAction of UIButton into the ViewController class

When I try to link the UIButton object to the ViewController class in order the create an IBAction, Xcode doesn't show me the window for creating it.
I have to say that It only happens with the second ViewController of the NavigationController, because with the first one it works.
I believe it should be a Xcode bug...
The situation is the one below:
In order for CTRL-drag to work, the ViewController must be told which ViewController class to use.
Once that is done, you can use split view and Control-drag from the button to the code. Xcode will not let you Control-drag to the wrong file.
You cannot control-drag from a button on View Controller 1 to the class file for View Controller 2.
I'm not sure if I see it all in the right way, but you have code for one view controller, which is called ViewController. In this view controller you have an action method for the button via avanti and an action method for the button via indietro. However, the buttons are not in the same scene of your story board. You have the first scene with the button via avanti linked with the ViewController.swift file (Controller initial scene), but the second scene (Controller finale scene) is not linked to your the ViewController.swift file, which it shouldn't. You have to create a new view controller file for every scene in your storyboard and put the action methods in the view controller files that are linked with the appropriate scene. It is also preferable not to call your view controller swift files ViewController.swift, but give them a meaningful name.
Hope this helps.
Kind regards,
MacUserT
the thing you are trying to add is the self.view which is already added in UIViewController Class. try adding another control like button or another UIView

Unable to add an action to my controller from storyboard 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:

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.

How see code-view for view controller in Xcode?

In my Xcode project, I have several view controllers in my storyboard. How can I see the code for a specific view controller?
Because each view controller will need to have different functions from the others. So, where can I write that code?
Thanks!
By default, storyboard will use UIViewController for the view controllers you use.
However you can change the class used for the view controller by:
selecting the view controller (in Interface Builder)
show the identity inspector (View > Utilities > Show identity inspector)
Change the value in Class to "MyOwnViewController"
Where "MyOwnViewController" is the name of the UIViewController subclass that you want to use for that view controller.
The "Show the Assistant editor" venn diagram icon on the top right did it for me.
Xcode Version 6.4
Select the View Controller you want to see the code
Go to the Assistant editor
It's on the upper bar to the right.
Select the storyboard in the navigator, right click and select 'Open As'. You should see 2 options 'Interface Builder - Storyboard' or 'Source Code' - select the Source Code option should fix your issue.
You subclass each UIViewController to add unique functionality. The implementation of UIViewController is private to Apple, the interface is described in it's documentation.
We start with multiple scenes in our storyboard.
see picture
Create new view controller file
Create new swift file
For our custom view controller
see picture
Setup file
In our new file,
Type in code
To set up class structure
see picture
link file to view controller in Storyboard
In Storyboard,
Click on our view controller
pic a
pic b
pic c
In the Identity Inspector,
In the Class field,
Type in the name of the new view controller file we created in step 1
open Assistant view
see pic
Done!
We are ready to write code
In our view controller
That is connected to our view controller in the Storyboard
see pic

Resources