Xcode 11 - I can connect actions but not outlets?

344 views Asked by At

Let me preface by saying that I haven't worked on any Xcode projects on this machine before. I normally work on a computer at my school, but I'm using another as I am away right now.

I was following along with a tutorial video from a Swift course that I'm taking, but I quickly realized that Xcode isn't giving me the option to connect any outlets. If I attempt to connect a UITextField, it only gives me the option to connect an action. If I attempt to connect a UILabel, it won't give me any options at all. I am used to being given the option to connect Outlets, Outlet Connections, and Actions on a UITextField (and UIButton) and being given the sole option of Outlet on a UILabel.

I've tried to fix the issue by setting the 'class' of the ViewController, but I didn't find any options for that.

Any advice would be greatly appreciated!!

attempting to connect UITextField Outlet

attempting to connect UILabel Outlet

UITextField not giving any option other than Action

Github repository - https://github.com/plates-the-one/noOutlet

3

There are 3 answers

0
matt On BEST ANSWER

My guess is that you are attempting to do all this in the wrong storyboard. Work in Main.storyboard, not in LaunchScreen.storyboard.

Also it is crucial that you select the Identity inspector in the storyboard and change the Class from UIViewController to ViewController.

0
Nico S. On

Sometimes Xcode is picky when a custom class is specified in the storyboard. A workaround is to write the @IBOutlet manually and the connect it to the UI element in the storyboard

1
Teju Amirthi On

I think when you are drawing a outlet, must be some issue with the type.

When you see the below outlet connection popup, change the type of the view from Any to the respective UIView type(UITextField and UILabel in your case)

Don't forget to change the connection from Action to outlet after you have changed the type

This must solve your issue. Comment if it solves your problem

Change Type from Any to UITextField/UILabel