Unable to drag item from storyboard to viewcontroller in xcode

I started working with xcode a few days ago, and today I tried to connect a text view from the main storyboard to the view manager, but I realized that it was not working.

I can ctrl + click to drag an item, but could not place it in both viewcontroller.h and .m. I double-checked that its viewcontroller and not UIViewcontroller, so this is not the case.

I am using Yosemite 10.10 macro.

Any help would be appreciated.

+20
ios objective-c iphone xcode osx-yosemite yosemite
source share
13 answers

Select ViewController in the storyboard and change the name of the ViewController to the name in the .h or .m file, and then try ctrl + click and drag enter image description here

+25
source share

For beginners → make sure that you keep the Ctrl key pressed while dragging into the code. This can be easily missed.

+17
source share

For me, the solution was to click the "View" element in the drop-down menu, which displays all the sub-items for the controller.

Click on root mode

Just clicking on the controller image on the storyboard does not display correctly, "select" the controller for drag and drop, you need to select the base view.

+7
source share

Make sure that you are in the assistant editor mode (when the code and layout editor are nearby).

From Apple :

With Interface Builder open in the standard editor panel, select the control you want to configure and click the Assistant Editor button ( enter image description here ) on the toolbar of the workspace. The assistant editor opens a file for implementing your objects.

Drag the control from the control in Interface Builder to the implementation file. (In the screenshot, the assistant editor displays the view controller implementation file for the Warrior Button.) Xcode indicates where you can insert the action method into your code.

+6
source share

Try to select your presentation in the storyboard and click the personality inspector on the right side of the classroom. Enter a name for the view controller, and then drag the item from the storyboard to the view controller.

Hope it helps.

+1
source share

Note that dragging to anywhere in your code does not necessarily work. If you were unable to drag to create a connection in one place of your code, try dragging it to another place. For me, I tried to drag to add a connection in the middle of a function that didn't work. Moving to the beginning of a function line or between functions really worked.

Here, between functions, a connection is allowed.

The connection is not allowed inside the middle of the function

Note: I am on Xcode 9.1

+1
source share

Hey, I think you didn’t connect your viewController storyboard with the viewController class. check out the screenshot that "suhit" uploaded to your answer. I would like to tell you something more. When you need to connect any storyboard object with a class.

  • first go to the utility panel (right side), and then set the class there.
  • after that you can connect your controls using the class

Hope this helps you.

0
source share

Verify that the names in the Viewcontroller Identity Inspector and the .h, .m files match. It worked for me

0
source share

I am using Xcode 9.2. I had ViewControlled processed in sections using the keyword "extension". Apparently, you cannot control drag and drop into the ViewController extension. If you go to the top that is in the class definition, the drag and drop control works fine (if you did other things in this thread that the correct class is connected to the view controller.

0
source share

I had the same problem, I realized that I had chosen the wrong storyboard. If you created the application with the default settings, you will get two storyboards (Main and Launch Screen). Labels on the launch screen bulletin board cannot be dragged.

0
source share

Make sure that the element in question is associated with the file that you want to control, drag it to (specify the class in the identity inspector).

0
source share

I had to rename the class (from ViewController to ViewController2) of the ViewController.swift file, and change the user class (from ViewController to ViewController2) of the main storyboard view controller to make Ctrl-Drag-and-drop work again.

Renaming back to ViewController from ViewController 2 to ViewController.swift and Main Storyboard didn’t prevent Ctrl-Drag-and-drop, it continued to work after that.

0
source share

All Articles