NSTextField: Multiple Inputs

Discussion in 'Mac Programming' started by Yellowstone2012, Jun 24, 2011.

  1. macrumors regular

    Joined:
    Feb 3, 2011
    #1
    This has been bugging me; how do I set a NSTextField to output a string from multiple NSTextFields?

    In VB.NET you could do this:

    Code:
    TextBox1.Text = TextBox2.Text & TextBox3.Text

    I am wanting to know how to do the same with Obj-C. I would also like to know the code such as to create a new line in string. (TextBox1.Text = "Test" & vbNewLine ; code for new line in visual basic)

    Thanks!
     
  2. macrumors 65816

    jiminaus

    Joined:
    Dec 16, 2010
    Location:
    Sydney
    #2
    Code:
    textBox1.stringValue = 
      [textBox2.stringValue stringByAppendingString:textBox3.stringValue];
    
    Code:
    textBox1.stringValue = @"Test\n";
    
    This is basic stuff. You should pick up a good book on Objective-C and Cocoa programming.
     
  3. macrumors 6502a

    Joined:
    Dec 2, 2008
    #3
    Cocoa

    I see jiminaus has beaten me to the punch. [NSString stringByAppendingString] is the way to go.

    More importantly, as jiminaus says, is to get very, very comfortable with surfing the Cocoa documentation. Get used to looking up a class and just paging through the methods. Cocoa naming conventions are fairly consistent and human readable, so this is a good technique.

    To get to the docs, in Xcode go to Window / Organizer / Documentation. Type NSString in the search bubble. Then in the breadcrumb trail at the top of the screen click on NSString Class Reference, select instance methods, and read.
     
  4. thread starter macrumors regular

    Joined:
    Feb 3, 2011
    #4
    Thanks for the code!

    Which book do you recommend? Thanks!
     
  5. macrumors 65816

    jiminaus

    Joined:
    Dec 16, 2010
    Location:
    Sydney
  6. thread starter macrumors regular

    Joined:
    Feb 3, 2011
    #6
    Thanks. I've just looked through the docs and found
    [stringByAppendingFormat:mad:" %@ %@", ...];

    I wrote the code, and my test app does exactly what I want it to do. It's printing my first name, space, and last name into another NSTextField. (label)

    I could just learn it on my own via the documentation.

    @"Thanks for the help!";
     
  7. macrumors 65816

    jiminaus

    Joined:
    Dec 16, 2010
    Location:
    Sydney
    #7
    That's fine. But don't forgot to search Google and the forum before asking a question.
     

Share This Page