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
andB
, and a storyboard: I would need to ensure that the storyboard is set to a class. If I set it toA
, it would only connect elements to classA
, if I set the class toB
, attempting to connect elements to classA
would have a blue line but noInsert Outlet or Action
orConnect Outlet/Action
.A visual representation:
Here we have declared two classes,
FirstClass
andSecondClass
. If you look at your blank storyboard (Main.storyboard
for the purpose of this answer), you should see something similar to as follows: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.
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
orSecondClass
, 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 toFirstClass
(with any luck autocompletion should finish it for you):Now, Control+Dragging an element from the Interface Builder to
FirstClass
should work, but will not apply toSecondClass
. Change the custom class name to whichever class suits your needs.