NSTextField setStringValue:将字符串追加到NSTextField [英] NSTextField setStringValue: append strings to NSTextField

查看:534
本文介绍了NSTextField setStringValue:将字符串追加到NSTextField的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有十个按钮,每个都有不同的名称。在选择每个按钮,我需要将按钮的标题附加到NSTextField,而不删除旧的字符串。

I have some 10 buttons with different names each.On selecting each button I need to append the button's title to NSTextField without removing the older string.

- (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]];
    }
}


$ b

这里的resultField是我的NSTextField。

Here resultField is my NSTextField.

setStringValue重写新的字符串,所以我不能附加字符串到NSTextField.Is有任何简单的方法来实现这个或者使用NSString值保存上一个字符串,并将此字符串NSTextFile和新按钮的字符串值。

setStringValue overriding the new string,so that I couldnot able to append string to NSTextField.Is there any easy way to implement this or else use NSString value to hold the previous string and set this string to NSTextFiled along with new button's string value.

推荐答案

如:

[resultField setStringValue: 
    [NSString stringWithFormat: @"%@ %@", [resultField stringValue], [sender title]];

这里的想法是,你拿你的NSTextField的原始内容,并通过 stringWithFormat ,然后将该新字符串分配给您的NSTextField。

The idea here is that you take the original content of your NSTextField and compose a new string via stringWithFormat and then assign that new string to your NSTextField.

这篇关于NSTextField setStringValue:将字符串追加到NSTextField的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆