NSString和NSTextfield的东西

时间:2010-10-27 13:52:28

标签: objective-c cocoa string macos textfield

我有这样的事情:

我的应用程序有NSTextfield名为userName,NSTextfield名为helloName,NSButton启动整个过程。它只是用户在名称文本字段中输入他/她的名字。 当用户按下确认时,Hello文本字段将显示“Hello,userName”之类的内容,而userName是直接从Name文本字段中获取的字符串。

我知道有一种方法可以从Name文本字段中获取字符串值,并使用%@将该值添加到句子“Hello,userName”中。但我无法在任何地方找到它......

1 个答案:

答案 0 :(得分:2)

您正在寻找[NSString stringWithFormat:]

NSString* helloSentence = [NSString stringWithFormat:@"Hello, %@", [userName stringValue];