Need direction on my first GUI based app.

Discussion in 'Mac Programming' started by thejadedmonkey, Aug 19, 2008.

  1. thejadedmonkey macrumors 604

    thejadedmonkey

    Joined:
    May 28, 2005
    Location:
    Pa
    #1
    The idea is really simple: The user enters how much money they need to save, how much money they have, and a pie chart appears below along with the text of how much they still have to save.

    I poked around with xcode, and now I have a GUI.. but I have no idea how to write the actual code to link the GUI to the back-end, or where the back-end code even gets written! As you can tell, I'm a n00b at xcode.

    Here's what I'm asking for.
    • Where do I go to write the actual code?
    • Is there an easy way to make a pie-chart?
    • How do I link the GUI to the actual code of the program?
    • What else do you think I should know?

    I've attached screen shots of what I'm trying to do, and what I have.
    If this is too needy of a request, I apologize in advance. Also, if you have a good link to a tutorial that would help, I'll take that too, I just can't seem to find a good tutorial that'll transform my java abilities into xcode. :(
     

    Attached Files:

  2. whooleytoo macrumors 603

    whooleytoo

    Joined:
    Aug 2, 2002
    Location:
    Cork, Ireland.
    #2
    I'm not sure if you're writing the project in Java or Objective-C, if it's Java I can't help you so I'll give you the Obj-C tips and you're on your own! :p

    For this, it's important to understand IBOutlets and IBActions. IBOutlets are pointers to interface items, such as windows, views, textfields etc. IBActions are methods which are triggered by interface items, such as buttons.

    Here are some steps to get you going:
    - Create a new OSX, Cocoa Application project.
    - Click on the Classes group, right click and select "Add>New File…"
    - Select Cocoa>Objective-C class
    - Give it a name (for now, try "MyWindowController")

    We'll use this class to "control" the window.

    - Next, open the Resources group, and open MainMenu.xib>English
    - In the Library View, click on "Objects and Controllers"
    - Drag an NSObject icon to your MainMenu.xib window.
    - Select this NSObject, and hit Cmd-6 (to open the Identity Pane)
    - In the Classes textfield, enter "MyWindowController" and press Return.

    We've now created an instance of "MyWindowController", now we need to customise it:

    - In the Identity Pane, click the "+" in Actions to create a new Action.
    - Call it "updateUI:" for now (NOTE: you must have the colon at the end!), and press Return.
    - Click the "+" in Class Outlets to create a new outlet.
    - Call it "needTextField", and change its type to "NSTextField", and press Return
    - Likewise, create a second textField, change its type, and call it "saveTextField".

    Next, we need to create the interface:

    - Drag two NSTextFields from the Library to your window. Size and name them as you wish.
    - Drag an NSButton to the window, and name and size as you wish.

    Now, we need to "link" the interface to the action and outlets we created earlier.

    - Hold the Ctrl button, and drag from the button to the NSObject (MyWindowController) we created. A pop menu will appear, click on "updateUI:".
    - Hold the Ctrl button, and drag from the NSObject to the first text field, select "saveTextField" from the popup.
    - Repeat for the second textfield, but select "needTextField".

    All done, we just need to tell Interface Builder to update the code files.

    - Click on the object, then go to the File menu and select Write Class Files…
    - If it asks you to replace or merge the files, select Replace.
    - If it asks you to add the file to the project, select it and click ok.

    In Xcode, you now have a class with an IBAction, and two connected IBOutlets.

    When the button is clicked, the updateUI: method will run. If you want to access the text fields, you can use [saveTextField stringValue].

    If you want code to execute on launch, try adding a

    - (void) awakeFromNib

    method to MyWindowController.m, and perform your initialisation there.

    That should be enough to get you started. Good luck coding!
     
  3. toddburch macrumors 6502a

    Joined:
    Dec 4, 2006
    Location:
    Katy, Texas
    #3
    Whooleytoo, you're a better person than me. I would have stopped after saying "you need to find an Interface Builder tutorial." (as opposed to writing one!)

    :)

    Todd
     
  4. whooleytoo macrumors 603

    whooleytoo

    Joined:
    Aug 2, 2002
    Location:
    Cork, Ireland.
    #4
    :p

    I'm just waiting for him/her to come back saying "No I need one for Java actually. Thanks!"
     
  5. 5fingers macrumors newbie

    Joined:
    Aug 20, 2008
    #5
    Thanks for the great information. I have an idea for an app was searching for information on where to start or what to do. Your post is a great starting point.
     

Share This Page