I made a Cocoa program that lets the user enter their name in NSTextField. When the user presses a button, another textbox is s开发者_运维百科upposed 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?
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'.
精彩评论