开发者

Displaying a string in Cococa

开发者 https://www.devze.com 2023-01-05 16:27 出处:网络
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

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'.

0

精彩评论

暂无评论...
验证码 换一张
取 消