简体   繁体   English

将文本添加到NSTextView时如何使用格式代码

[英]How do I use format codes when adding text to a NSTextView

I have a NSTextview called 'output' and it is set to non editable. 我有一个名为“输出”的NSTextview,它设置为不可编辑。 I use 我用

[self.output setString:[self.output.string stringByAppendingString:@"My string"]];

to add text to it. 向其中添加文本。 My question is, how to I use format codes in it? 我的问题是,如何在其中使用格式代码? Example

[self.output setString:[self.output.string stringByAppendingString:@"%d",myInt]];

This throws error : Too many arguments to method call, expected 1, have 2. Is there any way to do this without an error? 这将引发错误:方法调用的参数过多,预​​期为1,必须为2。有没有办法做到这一点而不会出错?

您真正想要的是stringByAppendingFormat而不是stringByAppendingString。

[self.output setString:[self.output.string stringByAppendingFormat:@"%d",myInt]];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM