tags:

views:

23

answers:

1

I made a Cocoa program that lets the user enter their name in NSTextField. When the user presses a button, another textbox is supposed to say Hello to them. This is the code I tried to use.

NSString *myString = [textField stringValue];
[textView setString: @"Hello " myString];

This does not work. How can it be fixed?

+1  A: 

Try the 'stringWithFormat:' method of NSString:

[ textField2 setStringValue: [ NSString stringWithFormat: @"Hello %@", [ textField1 stringValue ] ] ]

You can also use the 'stringByAppendingString:' method.

By the way, there is no 'setString' method. It's 'setStringValue'.

Macmade
There is a setString method. I used what you wrote with setString and it works.
Phenom
There is a `setString:` method in NSTextView (see the NSText doc), which is what Phenom is sending that message to.
Peter Hosey