Why insert action appearing and not iBoutlet? - ios

Why is my IBoutlet not showing when I try to link a text field to the swift controller view it says insert action instead of IBOutlet. I'm not trying to add an action what is wrong with this new update Is anyone else having this issue.

In connection, currently, you have Action selected. Tap on it to open a dropdown and select Outlet.
Image Source : Here
UPDATE
in Type, you need to select your TextField Class, currently its set to Any. Once you change it, the outlet option will start showing.

Just copy this code and paste above viewDidLoad method.
#IBOutlet weak var passwordTextField: UITextField!
And click the small circle before this line and drag to your text field.
Note: Make sure you've set the view controller class name in storyboard

When you attach #IBActions (or #IBOutlets), you do not want to attach them to Exit Object on the View Controller.
What i get from your image is your class is not set
The problem might be that you are supposing you can form an action connection from a UITextfield in the scene of one view controller to a different view controller. You can't. You can form outlets and actions only between a view controller and the interface inside the same scene of your storyboard.
Make sure your View Controller's class is linked to your file, then go into the Assistant Editor making sure you selected Automatic.
If you have questions, let me know!

Verify that you are using Main.storyboard and not Launchscreen.storyboard

Related

Why doesn't xcode let me create an IBOutlet

I am trying to add an outlet for a button, but when I control drag the button into the viewController class, it only allows me to create an action. In the screenshot you can see that the connection type is grayed out and stuck on action. Why isnt it letting me add an outlet? this same issue happens for every object like labels and text fields.
It is probably because you need to connect the storyboard vc to the file.
Click on the storyboard vc -> Click tab on right -> Enter name of view controller file into Class (Where it is highlighted in the image)

Is it possible to create an #IBOutlet in a custom view?

I've created a view on the storyboard in one of my view controllers and realized that I'll need to reuse it. So I then created a subclass for UIView to consolidate the code. I've selected the view in the storyboard and changed the class to my custom view class. Now I want to create #IBOutlets for a couple of the components in the view (in this case, 2 text fields). When I try and drag&drop from storyboard to custom view file, the only thing it allows me to create is an #IBAction and #IBOutlet is grayed out.
I tried creating the #IBOutlet manually in code and then drag from the circle to the component on the storyboard. Everything seemed to work (i.e. I see the connection in the little black popup and also the circle next to the variable is filled in. But when I run the app, the 2 fields are nil.
Is there a reason why I can only create actions and not outlets? (I'm kind of new to iOS dev).
No XIB is needed
Manually write the IBOutlet in your custom UIView class, for example:
#IBOutlet weak var container: UIView!
Open the storyboard and select the custom view in the Document Outline panel on the left.
Open the Connections Inspector on the right. Drag from the Outlet to the custom view in the Document Outline panel to connect them.
If you want to reuse a UIView then best to create an xib of the view and a custom class of the UIView. Then change the file owner in xib class to your custom class. Then you can drag and drop IBOutlets of the components inside the view to custom class. In the storyboard you can use the custom view and change the name of the class of view to custom view. Now drag and drop the IBOutlets from the story board to UIView. You can see the tutorial video on how to do , I have made for you.
https://youtu.be/IrgH522lbfA

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 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.

how can i get the object of a button created with storyboard

I created a button on a view controller by dragging the icon of button in storyboard. I thought this would generate an object. is there an approach that I can get the id, i.e. the object of that button? Is there a method that we designate a label or identifier for that button and we can refer to it with certain methods?
Thanks in advance for answering.
When you drag a button from the object library onto your storyboard's scene, when that scene is instantiated at runtime, the object associated for that button will be created. If you want to have a reference to that object so you can interact with it programmatically, you can open the assistant editor:
You will want to make sure you set the custom class for your view controller and you simplify your life a little if you tell your assistant editor to "automatically" select choose the right associated .h file:
You can then control-drag (or right-click-drag) from the button down to assistant editor window and create either an outlet (an IBOutlet) or an action (an IBAction):
By doing that, you then have a reference to the button object that is created when the scene is instantiated.
Open Assistan Editor (Split View, so that you see Interface Builder on the Left and Your View Controller on the right.)
Ctrl-Klick & Drag on the button and drag it to the Controller (you'll see a blue line).
An IBOutlet will be generated in your ViewController and you can access it.

Resources