26

I used to be able to do this in XCode, and now suddenly I can't in a new project I've opened that was sent over by a friend.

Is there a particular setting I have to change to start this again?

I.e. there is a textbox I want to link via Code, and now I just can't. :(

Need help guys!

econclicks
  • 327
  • 1
  • 5
  • 11

6 Answers6

31

You most likely have an assistant editor window opened to a wrong class, you will need to check on your currently selected view controller and make sure that its the same that is opened in the assistant editor

Or in assistant editor, select automatic (check screenshot)

enter image description here

enter image description here

Omar Abdelhafith
  • 21,163
  • 5
  • 52
  • 56
  • 1
    Yup you are right :). Thanks. I hadn't declared that particular class as the right kind of class I was trying to drag. – econclicks Jul 01 '12 at 22:21
21

The solution for me was simply to press Ctrl while dragging...

Ronen Rabinovici
  • 8,680
  • 5
  • 34
  • 46
20

I was having the same issue and looked all over and couldn't find a good fix to the problem. What was happening when my Controllers were first generated they had the generic names FirstController. When I switched the names I didn't switch the value in the Custom Class area. To fix:

  1. Select View.xib
  2. Select File's Owner under placeholders. This should be on the left side of the screen with a yellow cube next to it.
  3. Select the third option on the utilities menu (Identity)
  4. Change the Custom Class class to the correct Controller name.

I know this wasn't the specific question's issue but I clicked on this question a few times so thought if someone had the same issue it might be helpful.

Hennish
  • 685
  • 6
  • 10
  • 2
    This was my specific issue. I was working with Xamarin studio and I renamed a controller and it's xib, without updating the underlying markup of the xib. I manually updated the xib file to correct the behavior. – Nathan Taylor Jun 26 '15 at 00:33
  • 1
    This saved me a huge headache - I was trying to create a custom UIView class and could not link the main container view to the Swift class file until I did this. Thanks! – Alex Wulff May 22 '18 at 02:43
3

With the latest version of Xcode when I open up the Storyboard and .h file, I remove the last space below the @end tag on the bottom of the (fresh) .h file. Which for some reason wouldn't let me place the outlet after doing so, thanks Apple!

So to fix my problem i have to have that extra space below the @end tag in the .h file.

This is what fixed my problem and I know it doesn't answer this specific question but hopefully, it helps someone.

Lazar Kukolj
  • 696
  • 3
  • 15
  • 43
2

I had the same problem, In my case there was a mismatch between my class name at the identity inspector and that one at source code.

Dania Delbani
  • 816
  • 1
  • 11
  • 27
1

Had this issue too. XCode 9: make sure in the Storyboard -> Identity Inspector -> "Inherit from Module from Target" is checked (or fill out the module name manually)

EDIT: Turns out checking that box doesn't help -- if you delete the class of the UIViewController, then type it in manually and hit Enter, in XCode 9 if there's a problem the checkbox "Inherit Module from Target" will not auto check itself. After trial and error it turned out in the class (Swift 4), there was a #if IDENTIFIER .... #endif which was perfectly valid, but screwed up Storyboard connections some how. After removing it, typing the class name in the storyboard auto-checked the box, and now connections work. Yay another XCode 9 bug.

xaphod
  • 6,392
  • 2
  • 37
  • 45