Reputation: 184
I use Xcode 7.2
I can use Control+drag to swift file to create a @IBOutlet
But I can't drag @IBOutlet in swift file to storyboard. Here I don't use any other key, just drag.
Actually when I moving mouse to the spot before @IBOutlet, nothing happened and when I trying to drag it a breakpoint added.
1.I`m sure I use the right Class name
2.My project is not in a strange path or name
Upvotes: 6
Views: 4180
Reputation: 11
I ran into the same problem and the following solved the issue: The IBOutlet's ViewController class file cannot connect to the Main.storyboard file because the name of the ViewController class was renamed instead of refactored. Try refactoring names to make changes everywhere in the file instead of just renaming the names in the file. Otherwise xml tags of Main.storyboard will still contain the old values. This is why it fails to establish a connection between the two files when dragging the IBOutlet's circle icons to the respective UIElement in the Main.storyboard file.
Upvotes: 0
Reputation: 13181
The behavior has changed in new versions of Xcode (I'm not certain but it might have been since 7+.). Older versions of the product might still have the gutter shortcut working.
Now you have to either open the Connections Inspector or right-click on the view controller in the Document Outline. Once open, drag from the defined IBOutlet to your UIView subclass (UIButton, UITextField, etc...)
Search your local help for: Interface Builder Connections Help: Creating an Outlet Connection. You will find these are the only methods that now work. The gutter shortcut does not work.
Nota Bene:
You can confirm this behavior and other changes to Xcode shortcuts by choosing the following menu Help > Xcode Overview and taking a look at Part V: Building a User Interface, section Connecting Objects In Code.
Upvotes: 2
Reputation: 132
don't use Control, only drag with mouse from circle icons.You can see in the picture below. Circle icons in red box
Upvotes: 2