Search code examples
swiftxcodexcode-storyboard

Xcode 9 shows menu on Ctrl+drag


This must be very simple, but Xcode is really frustrating me. On literally my very first iOS app ever:

  1. Create new project, using Single View App template.
  2. Open main.storyboard and ViewController.swift side by side.
  3. Drop a button and position it.
  4. Now, to create the outlet to respond to my button click, I understand that I'm supposed to hold down control while dragging the button to the editor. This works approximately one time in ten. Instead, any attempt to click or control-click on the button, Xcode throws up this silly menu: Menu on control-click

For the life of me, I don't understand why this happens and I don't understand why this menu pops up and how to avoid it, but it means I can't use the control-drag feature at all.

I should add that I'm using a 2017 Macbook Pro with a touch bar and that I don't have problems dragging and dropping in any other app, nor in Xcode in any other circumstance.

I can see that it wants me to select either the control or one of its parents, but how do I drag when the menu pops up?


Solution

  • Like sanjaykmwt has said. That menu only shows up if you press the shift button while control-dragging.

    The menu is for you select views that are underneath (covered by) other views. Sometimes you might have trouble selecting certain views if they are under other views, right? That's when you shift+control+click and the menu will show you all the views that are on top of each other. In your screenshot, the button is onto of the UIView and the UIView is on top of the UIViewController.

    Another way to do control-drag is to do a right-click drag. If you haven't noticed already, control+click is equal to a right-click.

    You can also try connecting the outlet using the connections inspector:

    enter image description here

    Drag the circle next to "New Referencing Outlet" into the assistant editor normally.