XCode 4.4 and IBOutlets+Actions

Discussion in 'Mac Programming' started by Meldar, Sep 4, 2012.

  1. Meldar, Sep 4, 2012
    Last edited: Sep 4, 2012

    Meldar macrumors regular

    Meldar

    Joined:
    May 3, 2008
    Location:
    pocket of liberalism in farm country
    #1
    I wrote an application for OSX 10.6.8 a month or two ago. It worked fine. I used XCode 3.2.6 to write it and had a bunch of .h and .m files with IBOutlets and IBActions that I connected easily to the buttons and stuff they had to reference.

    XCode 4.4 comes along when I upgrade to Mountain Lion and suddenly everything is broken. I have found absolutely nothing of help on the internet. The closest I've come to finding a solution is someone telling me to change the "File's Owner" to a different class, which makes absolutely no sense as I have almost 10 unique classes with their own IBOutlets and IBActions.

    Ok so, since I can't explain it well, the project is set up like this:

    [​IMG]

    When I try to connect outlets, actions, and references, it only gives me the option to connect "bindings."

    And when I did (for fun) change the class of File's Owner to "OpenReadMe" instead of NSApplication, it threw that error message in the bottom right (though I did finally get the darn thing to compile)

    What exactly am I missing? I have NEVER found myself confronted with a piece of Apple software that is hard for me to use and doesn't strike me as intuitive.
     
  2. PatrickCocoa macrumors 6502a

    Joined:
    Dec 2, 2008
    #2
    Step by step

    I've used Xcode on a hobby level since version 2 and haven't had any problems like you describe (projects created under an old version and opened in a new version). That doesn't directly help you, but I don't think there's anything you need to manually change once you've opened the old project in the new Xcode.

    Method 1: try again
    You may want to go back to your original, untouched .xcodeproj created in 3.2.6. Use Time Machine if you don't have it. Open it in 3.2.6 and run it to make sure it runs. Then open it in 4.4 and run it.

    Method 2: step by step
    If method 1 doesn't work, go back to your untouched .xcodeproj in 3.2.6. Then download various intermediate Xcodes, and open the project in each, making sure to run after opening.
     
  3. klaxamazoo macrumors 6502

    Joined:
    Sep 8, 2006
    #3
    What error messages are you getting?

    Were you using any third party frameworks? If so, you might need to re-import them as the frameworks in Xcode 4.4 are in a different location.
     
  4. Meldar thread starter macrumors regular

    Meldar

    Joined:
    May 3, 2008
    Location:
    pocket of liberalism in farm country
    #4
    I created a new project. It's a long story, but I like fresh starts.

    I'm using the Cocoa framework and the GMP (multiple-precision integer) library. The latter is linked properly (after quite a lot of hair pulling and bundling).

    I don't think I explained my problem well.

    I can't link outlets or actions. It just asks to connect bindings, and I don't know what those are!

    The documentation says to simply click and drag. That isn't working. It does nothing.
     
  5. szymczyk macrumors regular

    Joined:
    Mar 5, 2006
    #5
    Are you making connections from user interface elements to outlets in your header file? If so, that would explain why Xcode is only giving you an option to connect bindings.

    If you're trying to connect buttons, just do what you would do in Xcode 3.2. Make a connection from one button to another and don't drag to the header file.

    If you're trying to create new outlets and actions by dragging to your header file, drag to the area between the closing brace in the @interface section and @end in the header file. If there are no braces in your @interface section, drag to the area between @interface and @end in the header file.
     
  6. Meldar thread starter macrumors regular

    Meldar

    Joined:
    May 3, 2008
    Location:
    pocket of liberalism in farm country
    #6
    The way I've interpreted that is that I should not have written the outlets and actions into the code already, but rather simply drag into the file to create them. Yes/no?

    I'll have to try that later - not at my coding Mac at the moment. At any rate, there is no good reason for this to not be working. I clearly messed up somewhere, but it's not a version difference issue since this is a new project...

    Ah well. I'll keep trying.
     
  7. szymczyk macrumors regular

    Joined:
    Mar 5, 2006
    #7
    There are two options. One option is the answer Yes to your question. Don't write code for the outlets and actions. Drag into the file to create the outlets and actions.

    The second option is to add the outlets and actions to your code. Drag to a UI element instead of the header file to make the connection.
     
  8. Meldar, Sep 6, 2012
    Last edited: Sep 6, 2012

    Meldar thread starter macrumors regular

    Meldar

    Joined:
    May 3, 2008
    Location:
    pocket of liberalism in farm country
    #8
    It's dragging from a UI element that gives me only the option "connect bindings," not "Connect outlet/action" whatever the case may be.

    Dragging tothe UI element gives absolutely no options at all...

    What on earth...I mean really. Is something wrong with my project setup, or what?

    I even tried making another file from scratch. Nothing. No option to drag anything anywhere with any tangible results.
     
  9. Meldar thread starter macrumors regular

    Meldar

    Joined:
    May 3, 2008
    Location:
    pocket of liberalism in farm country
    #9
    It will let me create stuff in the appDelegate header, but nowhere else. How utterly useless.

    I miss the previous version of XCode, which actually worked. I would create a class with .h and .m files, and it would appear as an object in the IB from which I could then simply drag outlets and actions. Now, I can't even figure out how to make my class files into an object that IB will see.

    How does anyone use this IDE? It's so annoyingly unintuitive. Unless there's something terribly wrong with my installation, I'm getting almost too frustrated to continue.

    Not like I've been having much luck with Visual Studio 2010 either.
     
  10. szymczyk macrumors regular

    Joined:
    Mar 5, 2006
    #10
    Drag an Object from the object library to the canvas. If you choose Objects and Controllers from the menu at the top of the object library, the Object item is the first item in the group. Select the Object you added from the object list on the left side of the editor. Open the identity inspector. Choose View > Utilities > Show Identity Inspector to access the identity inspector. Enter the name of your class in the Class combo box.

    Are you dragging from your code to the UI element? When I was talking about dragging to UI elements, I meant dragging from one UI element to another. In your initial post, I thought you were talking about connecting buttons to each other since Xcode 3.2 didn't have a way to make a connection from code to a UI element.
     
  11. Meldar thread starter macrumors regular

    Meldar

    Joined:
    May 3, 2008
    Location:
    pocket of liberalism in farm country
    #11
    Okay. I've already designed the GUI by dragging what you call Objects to the canvas - NSButtons and an NSTextField mainly, it's a very simple layout.

    I can't change the class of an NSButton to, say, one of my classes. Only other types of buttons (3 options only).

    Are you saying that if I have a class called myClass, I am to drag a button to the canvas, open the Identity inspector, and change its class to myClass instead of NSButton? That seems simple enough, but it doesn't work.

    I was trying to. The limited XCode documentation implied that I could. I can't.
     
  12. szymczyk macrumors regular

    Joined:
    Mar 5, 2006
    #12
    Dragging an Object to the canvas creates an instance of your class in the xib file. This allows you to make connections to your class in Interface Builder (Xcode).

    If you drag a button to a window, you are not going to be able to set the class of the button to your class unless your class is a subclass of NSButton. This applies to all UI elements. You won't be able to set the class of a UI element to your class unless your class is a subclass of the appropriate class.
     
  13. Meldar thread starter macrumors regular

    Meldar

    Joined:
    May 3, 2008
    Location:
    pocket of liberalism in farm country
    #13
    I knew that. That's how it worked in the previous version. At least, if you meant that my class suddenly appears in IB as one of those blue cubes used to represent Objects.

    That's what I was trying to ask. In the previous versions of XCode, if I wrote a class, I could code in connections and outlets and then the class itself would show up in IB.

    For example, I have a simple button command that opens the readme.rtf file. It is a subclass of NSObject. Making it a subclass of NSButton solves nothing (although I take it that is the wrong approach).

    Gah. I'm sorry if I'm frustrating you. This must be a simple thing that I'm just not getting. I refuse to believe that Apple would make something that doesn't Just Work™, but then again, it could just be me.
     
  14. Meldar thread starter macrumors regular

    Meldar

    Joined:
    May 3, 2008
    Location:
    pocket of liberalism in farm country
    #14
    DUH

    That's what I meant all along.

    Sorry if I wasted your time! I think I can handle it from here!!

    It was a "me" problem after all. Ah well, it's a new version to me. Sometimes I catch on quickly. Other times, well...

    Have a nice day :)
     
  15. szymczyk macrumors regular

    Joined:
    Mar 5, 2006
    #15
    I did a small test in case you run into other problems. I created a Cocoa project and added a class, TestClass, to the project. In the header file I added an outlet, testOutlet, and an action, doSomething, to the class. In the xib file I added a button. I dragged an Object item (blue cube) to the xib file and set the class to TestClass.

    At this point I tested connections. If I drag from the Object (blue cube) to the button, I can set the outlet to testOutlet. If I drag from the button to the Object, I can set the action to doSomething.

    I switched to the assistant editor and opened TestClass.h to test if I could connect to the header file. If I drag from the button to testOutlet or doSomething, I had the option to make the connection. If I dragged between @interface and @end in the header file, I could insert a new outlet or action.
     

Share This Page