12

I am unable to set a referencing outlet for a text field I have created. I am trying to do this via Ctrl-Drag. Can anyone advise? I have set the delegate as the View Controller. In general, I only have one view which is populated with a few text fields and I have written the following code for the ViewController.h which is what I'm trying to set up as a Referencing Outlet:

@property (weak, nonatomic) IBOutlet UITextField *userIDText;
vfvfvfvfvfvfvfvfv
  • 143
  • 1
  • 1
  • 7
  • 1
    Did you Ctrl-Drag to it, or just write that code? – Linuxios Nov 18 '14 at 22:20
  • I meant to say Ctrl-Drag was not working...I am not getting the little pop-up option to set View Controller as a referencing outlet – vfvfvfvfvfvfvfvfv Nov 18 '14 at 22:21
  • 1
    In other words, I did try to ctrl drag it but that wasn't working and I wasn't sure why – vfvfvfvfvfvfvfvfv Nov 18 '14 at 22:31
  • 2
    Have you set the IB View Controller to be your View Controller subclass? After you've done this you should be able to link the IBOutlet to the control or even Control-Drag to create a new outlet. If you are new to iOS development I strongly urge you to follow some tutorials as this is very basic. – Robotic Cat Nov 18 '14 at 22:58

3 Answers3

14

First, make sure the control you're dragging from is the same class as the outlet (in this case, UITextField) or it could be a subclass of that class.

Second, make sure control's parent view is a subclass of the file you're dragging to.

Third, make sure the file you're dragging to is saved. This is the most common problem I run into. Go to the source file you're dragging to and push Cmd+S to save.

Fourth, when in doubt, Cmd+Shift+K to clean, Cmd+B to build, then try again. If that still doesn't work, restart Xcode. And if it's still not working, go back through the checklist.

nhgrif
  • 61,578
  • 25
  • 134
  • 173
  • Inmy case Ic ould not drag & drop between the source code file and the interfacebuilder. Maybe because it was too deeply nested. But I could drag & drop from the viewcontroller in the interface builder to its sub elements. – Torge Jan 11 '17 at 16:34
8

In my case, to be able to create a referencing outlet,

  1. I had to open the Storyboard.
  2. Click on the top View Controller element (left panel in the Storyboard)
  3. In the Identity Inspector (right panel), I had to select from the list my custom view controller class before I could drag and create the referencing outlet in it.
dev4life
  • 10,785
  • 6
  • 60
  • 73
1

In my cace,(swift3) 1.right click on the storyboard. 2.Ctrl-Drag from black window and ReferencingOutlet to View on the storyboard. enter image description here

Hideyasu.T
  • 809
  • 6
  • 5