Can't drag and drop item from storyboard to vi

2019-03-12 17:11发布

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.

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

I'm using a Yosemite 10.10 mac.

Any kind of help would be appreciated.

11条回答
欢心
2楼-- · 2019-03-12 17:55

I had same problem, I realised I selected wrong story board. If you made app with default settings you will get two story boards (Main and Launch Screen). Labels on Launch screen story board cannot drag drop.

查看更多
欢心
3楼-- · 2019-03-12 18:02

Try this

Select your view in storyboard and click on identity inspector on right side in class enter your view controller name and then drag and drop item from storyboard to view controller then it will work.

Hope it helps.

查看更多
Juvenile、少年°
4楼-- · 2019-03-12 18:03

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.

查看更多
Rolldiameter
5楼-- · 2019-03-12 18:06

Hey I think you are not connected your storyboard viewController with your viewController class. check screen shot which "suhit" uploaded in his answer. I would like to tell you something more than it. When ever you need to connect any storyboard object with class.

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

I hope it will help you.

查看更多
乱世女痞
6楼-- · 2019-03-12 18:08

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 (enter image description here) 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.

查看更多
登录 后发表回答