名前がそれぞれ異なる10個のボタンがそれぞれあります。各ボタンを選択すると、古い文字列を削除せずにボタンのタイトルをNSTextFieldに追加する必要があります。NSTextField setStringValue:NSTextFieldに文字列を追加する
私は次の方法で試しました。
- (IBAction)nextButton:(NSButton*)sender
{
int tag = [sender tag];
if (tag==1) {
[resultField setStringValue:[sender title]];
}
else if (tag==2) {
[resultField setStringValue:[sender title]];
}
else if (tag==3) {
[resultField setStringValue:[sender title]];
}
else if (tag==4) {
[resultField setStringValue:[sender title]];
}
else if (tag==5) {
[resultField setStringValue:[sender title]];
}
else if (tag==6) {
[resultField setStringValue:[sender title]];
}
else if (tag==7) {
[resultField setStringValue:[sender title]];
}
else if (tag==8) {
[resultField setStringValue:[sender title]];
}
else if (tag==9) {
[resultField setStringValue:[sender title]];
}
else if (tag==10) {
[resultField setStringValue:[sender title]];
}
}
ここで、resultFieldは自分のNSTextFieldです。
setStringValue私はそこNSTextField.Isにこれを実装するための簡単な方法を文字列を追加したり、他の前の文字列を保持するためにNSStringの値を使用して、新しいボタンの文字列と一緒にNSTextFiledにこの文字列を設定することができcouldnotように、新しい文字列をオーバーライド値。
[resultField setStringValue:
[NSString stringWithFormat: @"%@ %@", [resultField stringValue], [sender title]];
ここでの考え方は、あなたのNSTextFieldの元のコンテンツを取るとstringWithFormat
を経由して、新しい文字列を構成して、あなたのNSTextFieldにその新しい文字列を割り当てることです:のようなものについてはどのように