MacOS – Xcode 6.1 , Storyboard, Ctrl+Drag doesnt work, not even blue line

macosxcode

I just upgraded to XCode 6.1

I started to create a Mac, Cocoa application.

In story board, i put a button on view controller, and tried to CTRL+DRAG it to the source code.

Problem is that it doesn't work, at least i have to see the blue line despite of where im going to drop it, but nothing happens at all and blue line doesnt appear and control stays put :-s

What am i doing wrong?

Best Answer

I realise I'm a bit late, but my solution to this problem was to ensure that the class that interface builder was "dragging to" was the same as the class that it was under: in other words, everything must be in the same class.

For example, if I have classes A and B, and a storyboard: I would need to ensure that the storyboard is set to a class. If I set it to A, it would only connect elements to class A, if I set the class to B, attempting to connect elements to class A would have a blue line but no Insert Outlet or Action or Connect Outlet/Action.


A visual representation:

ViewController.swift:

import Cocoa
class FirstClass: NSViewController {
    // some code here
}

class SecondClass: NSViewController {
    // some more code here
}

Here we have declared two classes, FirstClass and SecondClass. If you look at your blank storyboard (Main.storyboard for the purpose of this answer), you should see something similar to as follows:

Normal Main.storyboard look.

Now, click the window under the View Controller (blank on a new project), and select the tab that looks a bit like a newspaper in the Inspector.

View Controller and class.

You should see the default class (ViewController) formatted as a placeholder string in the text field for "Class". Attempting to Control+Drag would not allow you to create an instance of whatever element you're trying to add to either FirstClass or SecondClass, but only allow it for the class specified, ViewController (for some reason I can't screenshot it).

To add an element to FirstClass, change the text in the Class field to FirstClass (with any luck autocompletion should finish it for you): As seen

Now, Control+Dragging an element from the Interface Builder to FirstClass should work, but will not apply to SecondClass. Change the custom class name to whichever class suits your needs.