econclicks
econclicks

Reputation: 337

Can't drag outlets from Storyboard to Assistant editor in XCode

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!

Upvotes: 26

Views: 26593

Answers (6)

xaphod
xaphod

Reputation: 6794

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.

Upvotes: 1

Ronen Rabinovici
Ronen Rabinovici

Reputation: 9092

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

Upvotes: 21

Dania Delbani
Dania Delbani

Reputation: 826

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.

Upvotes: 2

Lazar Kukolj
Lazar Kukolj

Reputation: 706

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.

Upvotes: 3

Hennish
Hennish

Reputation: 683

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.

Upvotes: 20

Omar Abdelhafith
Omar Abdelhafith

Reputation: 21221

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

Upvotes: 31

Related Questions