How to add outlets to objects in interface

Discussion in 'Mac Programming' started by danfrex, Aug 13, 2011.

  1. danfrex macrumors newbie

    Joined:
    Aug 13, 2011
    #1
    This may be a simple question but I just started using Cocoa...I'm reading a Dummies book on Cocoa programming but it's not updated to the new version of XCode, so I don't understand after I add an NSObject to my project window how I add outlets to that object...in the old XCode you can simply add outlets and actions in the attributes window for that NSObject but that doesn't exist anymore in XCode 4.

    I know you have to use the Assistant editor somehow to link that object to a class but not sure how that would work. I tried that and I got errors for something else. Thanks for your time....
     
  2. jiminaus macrumors 65816

    jiminaus

    Joined:
    Dec 16, 2010
    Location:
    Sydney
    #2
    Read through the Designing User Interfaces in Xcode chapter of the XCode 4 User Guide. Particularly the Create and Manage Connections in Interface Builder section of that chapter has your answer, but you'd do well to familiarise yourself with the whole chapter (if not the whole guide).
     
  3. danfrex, Aug 13, 2011
    Last edited: Aug 13, 2011

    danfrex thread starter macrumors newbie

    Joined:
    Aug 13, 2011
    #3
    I figured out what to do, but I had to do it manually. I have read the user guide extensively but it doesn't specifically apply to what I want. What I did was I created a new class file, MyController, and then manually added the outlets in the header file. Then I ctrl-dragged to the respective features in the interface from the MyController object in the project window that I added. However, I also had to add property assigns (i.e. @property (assign) IBOutlet NSTextField *display;) to the AppDelegate header file for each outlet and the program eventually worked. I'm sure I'm doing this the long way but can anybody tell me how to properly do this in the new version of XCode, the exact concept I'm attempting? I understand what the Xcode guide is saying to do like you said jiminaus but it's not quite the same concept...thanks
     
  4. jiminaus, Aug 13, 2011
    Last edited: Aug 14, 2011

    jiminaus macrumors 65816

    jiminaus

    Joined:
    Dec 16, 2010
    Location:
    Sydney
    #4
    Basically it involves opening a header file in an assistant editor side-by-side with a xib file. Control-dragging an object from the xib file to the header file. Choose outlet, type in its name and finally click connect. Voila, you have an IBOutlet property connected to the object.

    This is all documented under the (first) subheading To create and connect a new outlet... of the section I pointed out. It even has a video showing the technique.

    You use a similar technique to create and connect a new IBAction. And guess what? It's documented in the following subheading To create and connect a new action....
     
  5. danfrex thread starter macrumors newbie

    Joined:
    Aug 13, 2011
    #5
    yep, I did this well before you recommended it....I don't know what the problem is but I'm doing exactly what you said. I have a MyController object in the xib window, and open up a MyController.h file with assistant editor. do a ctrl-drag from the object to the .h file and nothing shows up, no outlet option. However, dragging to the appDelegate.h file I do get the outlet option but that's not what I want. What am I doing wrong? Please don't tell me to read the guide or watch the video. I did before I even posted, man :eek:
     
  6. danfrex thread starter macrumors newbie

    Joined:
    Aug 13, 2011
    #6
    I'd like to reiterate that this is not working for me. I've done exactly as I have been told, dragging from the object in the nib menu to the header file, yet no option for an outlet. Once again, I do get the option when I drag from my MyController object in the interface to the AppDelegate Header file, but not when I drag to the MyController.h class I created. Any idea what I'm doing wrong?
     
  7. jiminaus macrumors 65816

    jiminaus

    Joined:
    Dec 16, 2010
    Location:
    Sydney
    #7
    You are holding down the control key when you're dragging, right? And you're dragging after the } (if there are { }) and before @end of the @interface section?
     
  8. danfrex thread starter macrumors newbie

    Joined:
    Aug 13, 2011
  9. danfrex thread starter macrumors newbie

    Joined:
    Aug 13, 2011
  10. jiminaus macrumors 65816

    jiminaus

    Joined:
    Dec 16, 2010
    Location:
    Sydney

Share This Page