1

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?

5 Answers 5

2

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.

0

If you right click on the button you must see a menu with button actions. Move the cursor over any circle and it will appear a Plus symbol. Select and drag to your source.

enter image description here

3
  • Hijherran, thanks for your answer. Actually i am aware of that, but my concern is why CTRL+DRAG doesnt work, that weird. I would like to use ctrl+drag as i used to
    – Aliss
    Nov 30, 2014 at 8:37
  • OK, but, could you see this menu when you right click?
    – jherran
    Nov 30, 2014 at 8:39
  • yes of course, i see this menu and when i drag circles beside menu items, i can see the blueline. but when i press ctrl and drag a control (buttton), that blue line doesnt appear.
    – Aliss
    Nov 30, 2014 at 10:29
0

I have not played with Storyboards much.

But I think you need to drag to the viewController.h file rather than the AppDelegate.h

1
  • Yes, you are right and i intend to do that, problem is that the blue line doesn't appear at first place, no matter where i am going to drag it to. Its not only in StoryBoard, i have same problem with xib files as well.
    – Aliss
    Nov 30, 2014 at 10:55
0

Well, i know its stupid, but i found the problem.

It doesnt work because im connecting to the Mac using VNC :( It seems connecting to Mac remotely , doesn't reproduce or simulate Keyboard keys and mouse clicks, even though i can see ctrl key goes down on "Keyboard Viewer" when i press ctrl, but something is wrong with VNC that prevent Xcode to act correctly.

I used two different VNC clients and none of them worked, I update this post if i can find a solution.

0

just delete everything inside DerivedData Folder (/Library/Developer/Xcode/DerivedData)

It worked for me :)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .