开发者

Displaying a string in Cococa

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜