I have two view controllers on the story board, I can connect one VC to code in one swift file, but can't connect the second. - ios

So, as my title describes, I can connect one view controller in my story board to the first view controller.swift file but unable to connect the second view controller in story board to my second view controller.swift file. Any reason for this? Am I missing something?
Thanks for any help,
Jon

You can add a ViewController-class to your ViewController in your Storyboard by following the steps below:
But you have to make sure that you have created your class correctly.
To do that do the following:
File->New->File->iOS-Source->Cocoa Touch
At Subclass of you have to choose: UIViewController
Add a name, click Next and Create
Now you can add your created controller like mentioned above.

Related

IBAction issue in Xcode StoryBoard

I'm a newbie in coding and I'm learning Swift to develop my first application.
I'm following this YT tutorial trying to integrate a SideMenu :
https://www.youtube.com/watch?v=iq-tWW45Vhk
The fact is that after I added the #IBAction func into my code like this:
I do not find the received action I create in the code like in the video at 4:47
I found out that this appears only in my first ViewController (the blue screen) of my StoryBoard but I want the function to appear on the top right view controller
Can someone help me?
Thx
Julien
For all viewControllers in story board you have to create separate swift class files, and create it's IBAction outlet in it's class file.
add viewController class here :
after this you will be able to create IBOutlet and IBActions in that class.
I found out that this appears only in my first ViewController (the blue screen) of my StoryBoard but I want the function to appear on the top right view controller Storyboard
You need to put the action in the view controller class where you want it to appear. If it's showing up somewhere else, it's in the wrong class.

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

How can I link an outlet from a view controller to an other?

I am working on an app that uses parse so I used the "starter project" as a base and worked from there.
The issue I am facing is that the ViewController is controlling the login screen a well as others such as the tableView and mapView witch I added later.
As this is the case if it would be possible I would link the map outlet by simply dragging from the code to the map but obviously this is not possible, How could I solve this problem (I understand I may be looking at the problem the wrong way but any help would be appreciated)
here is the code with the map outlet
here is what the layout looks like
The MVC model, Model-View-Controller model, isn't intended to have an action in one view touch the controller of another view. In InterfaceBuilder, you should only ever be able to attach actions to the controller for that specific view.
In general, if you set the file owner to ViewController, then you can only link IBoutlets to that view controller not make to another one.
your map is available in your MapViewController not ViewController, so you need to give the reference/IBoutlet of map need to assign the MapViewController, if you want to implement in ViewController, you need to create new one map
No you have to create different file for each controller.
you cant add outlet of all in one controller

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.

Connecting the view controller to the code in swift

When I create two view controllers in the main story board, how do I connect the second one to code?
An example would be:
I put a label in the first view controller called myLabel
I put another label in the second view controller called myLabelTwo
Now, the first view controller can connect to the code easily, but the second view controller 's myLabelTwo cannot be connected.
Create new UIViewController class, ViewController2 for example
In your storyboard, select your second view controller and on the right side menu click on "Show the identity inspector"
Change the Class content to "ViewController2" or whatever else.
You can now connect "myLabelTwo" to your "viewController2"
Please check this link to understand storyboard and view controllers.

Resources