PDA

View Full Version : NSTextField: Multiple Inputs




Yellowstone2012
Jun 24, 2011, 09:30 PM
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:

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!



jiminaus
Jun 24, 2011, 09:58 PM
textBox1.stringValue =
[textBox2.stringValue stringByAppendingString:textBox3.stringValue];



textBox1.stringValue = @"Test\n";


This is basic stuff. You should pick up a good book on Objective-C and Cocoa programming.

PatrickCocoa
Jun 24, 2011, 10:04 PM
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.

Yellowstone2012
Jun 24, 2011, 10:07 PM
textBox1.stringValue =
[textBox2.stringValue stringByAppendingString:textBox3.stringValue];



textBox1.stringValue = @"Test\n";


This is basic stuff. You should pick up a good book on Objective-C and Cocoa programming.

Thanks for the code!

Which book do you recommend? Thanks!

jiminaus
Jun 24, 2011, 10:11 PM
Which book do you recommend?


How do I get started programming on the Mac (or iPhone)? (http://guides.macrumors.com/Cocoa_FAQ)

Yellowstone2012
Jun 24, 2011, 10:28 PM
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.

Thanks. I've just looked through the docs and found
[stringByAppendingFormat:@" %@ %@", ...];

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)

How do I get started programming on the Mac (or iPhone)? (http://guides.macrumors.com/Cocoa_FAQ)

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

@"Thanks for the help!";

jiminaus
Jun 24, 2011, 10:33 PM
I could just learn it on my own via the documentation.


That's fine. But don't forgot to search Google and the forum before asking a question.