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.
Related
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
I often look up questions about Swift regarding formatting and Views, and answers I find will include lines of code. If I am using storyboards, where should I look to include code?
Thanks in advance.
You include code to it's corresponding class.
let's say you're using a UIViewController in storyboard:
make a class of type ViewController,
and put the class name for it
now both the class and the storyboard viewcontroller work together. and you can just add code in that class...
Adding onto slimboy's answer, if you are beginner, you might forget to connect the IBOutlets/IBActions. Here is how.
You switch to double pane view with the storyboard on the left and the view controller on the right.
Then ctrl click from the view element to the top of the view controller
Name you view whatever (myTitleLabel).
Now you can use code to refer to the myTitleLabel. IBAction works the same, but make sure to change the option to Action (default is outlet in Swift).
I've been trying to outline the basic functionality of a swift application I was developing. I created a basic gui with the storyboard functionality that xcode provides. Here is a picture of what it looks like currently:
What I want to do next is code up a way to receive and store input from the text fields I outlined in the storyboard. Additionally I want to receive information regarding certain settings that are placed from the switches I outlined in the second screen.
I've been looking through the files that xcode provides me but I haven't been able to find the one that contains the functionality for the storyboards. If someone could point me in the right direction for that i would greatly appreciate it. Ultimately I just want to be able to manage the input provided by the interface I outlined below. Thanks!
For each view controller on the storyboard make a subclasses of UIViewController.
In the inspector panel on the left of the storyboard set the class of each view controller to their respective subclass of UIViewController.
Open up the .swift file for that view controller and storyboard and ctrl + drag from the textField to the class this will cause a small popup where you can create an IBOutlet or IBAction.
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.
Im using story boards and in the Custom Class panel of the specific view controller if i give the name of the class that contains code for that view controller i get a blank screen. What could be the problem? Ive tried everything.
SO basically Class is usually UIViewController in CustomClass. I changed it to MenuScreenViewController(a ViewController objective C class that has code associated with this) and im calling it modally. Why do i get a blank screen. Urgent help please.
My guess, once again:
remove the implementation of - (void)loadView from your UIViewController subclass. You only need this method when you create your viewControllers view in code. When you create the view from a nib file or storyboard you must not have this method.
But it's not your fault, the implementation is there because of a bug in the Xcode 4.3 viewController templates.
EDIT: This bug is fixed in Xcode 4.3.2. The template does no longer contain - (void)loadView