Can't drag and drop item from storyboard to viewcontroller in xcode

前端 未结 13 1451
不知归路
不知归路 2021-02-02 10:54

I started working with xcode a few days ago, and today I tried to connect a textview from the main storyboard to the viewcontroller, but I figured out that its not working.

相关标签:
13条回答
  • 2021-02-02 11:39

    Try selecting your view in the storyboard and clicking on the identity inspector on the right side in class. Enter your view controller name and then drag and drop the item from the storyboard to the view controller.

    Hope it helps.

    0 讨论(0)
  • 2021-02-02 11:40

    I'm using Xcode 9.2 I had my ViewControlled refactored into sections using the "extension" keyword. It appears you can't control drag into an extension of a ViewController. If you go up to the top part that is in the class definition, control dragging works fine (assuming you did the other things in this thread about making sure the right class is associated with the view controller.

    0 讨论(0)
  • 2021-02-02 11:49

    For beginners -- > make sure you have kept the "Ctrl" key pressed down while dragging and dropping onto the code. This can be easily missed.

    0 讨论(0)
  • 2021-02-02 11:50

    Make sure you're in Assistant Editor Mode (When code and layout editor are side-by-side).

    From Apple:

    With Interface Builder open in the standard editor pane, select the control you want to configure, and click the Assistant Editor button () in the workspace toolbar. The assistant editor opens your object’s implementation file.

    Control-drag from the control in Interface Builder to the implementation file. (In the screenshot, the assistant editor displays the implementation file of the view controller for the Warrior button.) Xcode indicates where you can insert an action method in your code.

    0 讨论(0)
  • 2021-02-02 11:51

    Select the ViewController in 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

    0 讨论(0)
  • 2021-02-02 11:51

    I had to both rename the class (from ViewController to ViewController2) of the ViewController.swift file and change the Custom Class (from ViewController to ViewController2) of the Main Storyboard's View Controller to make Ctrl-Drag-and-drop work again.

    Renaming back to ViewController from ViewController 2 in ViewController.swift and Main Storyboard did not thwart the Ctrl-Drag-and-drop, it remained working afterward as well.

    0 讨论(0)
提交回复
热议问题