Some beginners help

Discussion in 'Mac Programming' started by jaikob, Dec 9, 2008.

  1. jaikob macrumors 6502

    jaikob

    Joined:
    Jul 1, 2008
    Location:
    Freeland, MI
    #1
    I am starting a cocoa objective-c application (My first). What I want to achieve is this:

    I have a textbox, I want to get the value of the textbox once a button is clicked, and display it in a different textbox.

    I have created an object, and specified actions for the button, and for the "inputfield". I set the "outputfield" as an outlet.

    If I use this code for the button action:

    Code:
    [outputfield setStringValue:@"This will be outputted"];
    It outputs the string defined. Well I want it to output the string in "inputfield" to the "outputfield" with the string "Number:" infront of it.

    So, if I type "1234" in inputfield I want it to display "Number: 1234" in the outputfield.


    I hope this is understandable.
     
  2. BravoBug macrumors newbie

    Joined:
    Dec 8, 2008
    Location:
    Oregon, USA
    #2
    You should take a look at the Apple docs for NSString, plenty of useful methods in there! Two examples:

    Code:
    [outputfield setStringValue:[@"Number:" stringByAppendingString: [inputfield stringValue]]];
    
    NSString *out = [NSString stringWithFormat: @"Number: %@", [inputfield stringValue]];
    [outputfield setStringValue: out];
    etc.
     
  3. themoonisdown09 macrumors 601

    themoonisdown09

    Joined:
    Nov 19, 2007
    Location:
    Georgia, USA
    #3
    I don't know if you have any books on Cocoa and Objective-C, but the book Cocoa Programming For Mac OS X by Aaron Hillegass is great for beginners. If you have XCode 3, then the third edition of the book is what you want.

    I've went through this book and it really helped me understand a lot of different things that I didn't know.
     
  4. jaikob thread starter macrumors 6502

    jaikob

    Joined:
    Jul 1, 2008
    Location:
    Freeland, MI
    #4
    Yeah, I'm going to purchase a book soon.

    When I use:

    Code:
    [outputfield setStringValue:[@"Number:" stringByAppendingString: [inputfield stringValue]]];
    It is telling me:

    error: 'inputfield' undeclared (first use in this function)
     
  5. themoonisdown09 macrumors 601

    themoonisdown09

    Joined:
    Nov 19, 2007
    Location:
    Georgia, USA
    #5
    Are you sure that you have the variable inputfield declared correctly in that function?
     
  6. jaikob thread starter macrumors 6502

    jaikob

    Joined:
    Jul 1, 2008
    Location:
    Freeland, MI
    #6
    In my header file it is specified like this:

    Code:
    - (IBAction)inputfield:(id)sender;
    What do you mean by declared?
     
  7. themoonisdown09 macrumors 601

    themoonisdown09

    Joined:
    Nov 19, 2007
    Location:
    Georgia, USA
    #7
    Ah... never mind. I think I read it wrong. I was thinking that inputfield was a variable, not a function. Plus, I'm in C# mode right now, not Objective-C.
     
  8. jaikob thread starter macrumors 6502

    jaikob

    Joined:
    Jul 1, 2008
    Location:
    Freeland, MI
  9. themoonisdown09 macrumors 601

    themoonisdown09

    Joined:
    Nov 19, 2007
    Location:
    Georgia, USA
    #9
    If you want to download all the projects from that Cocoa book I mentioned earlier, you can download it on the book's website here:

    http://bignerdranch.com/products.shtml

    Under the Cocoa Programming for Mac OS X title, you should see a link that says "Get the solutions".

    You can run the programs and look and see how everything works. The solutions are meant for XCode 3. Look at the project called RandomApp. It calculates a random number when you press a button, and displays the number in a text box.
     

Share This Page