在 NSRunAlertPanel 中显示 % 时遇到问题

发布于 2024-10-08 07:01:53 字数 302 浏览 0 评论 0原文

我正在开发一个桌面应用程序,我想使用 NSRunAlertPanel 在警报面板中显示一条消息。 我正在做以下事情:

NSString *title = @"% Test";
NSString *message = @"% Test Message";
NSRunAlertPanel(title, message, @"Ok" ,@"Cancel" ,nil);

警报面板正确显示标题。即%测试 但是,消息是est Message;我想显示%测试消息。

我该如何解决这个问题?

提前致谢。

I am developing an Desktop application where I want to show a message in alert panel using NSRunAlertPanel.
I am doing the following things:

NSString *title = @"% Test";
NSString *message = @"% Test Message";
NSRunAlertPanel(title, message, @"Ok" ,@"Cancel" ,nil);

The alert panel show the title properly. i.e % Test
But, the message is est Message; I want to display % Test Message.

How do I solve this problem?

Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

八巷 2024-10-15 07:01:53

试试这个:

NSString *title = @"% Test";
NSString *message = @"%% Test Message";
NSRunAlertPanel(title, message, @"Ok" ,@"Cancel" ,nil);

为什么?

NSRunAlertPanel 使用 NSBeginAlertSheet。查看 NSBeginAlertSheet的文档可以看到msg后面还有更多的参数(由...指定)。

这告诉我们,标题只是一个字面显示的字符串,但消息可以像 [NSString stringWithFormat:] 一样具有格式参数。

字符串指定参数的方式是使用 % 字符,即 %i 表示“在此处放置一个整数”,%@ 表示“在此处放置对象的描述” '。你只是单独加上了一个%,这让事情变得非常混乱!

双 %% 意味着这个百分比不是我告诉你我希望你在里面放一些特别的东西,我真的只是想要 %。

Try this :

NSString *title = @"% Test";
NSString *message = @"%% Test Message";
NSRunAlertPanel(title, message, @"Ok" ,@"Cancel" ,nil);

Why?

NSRunAlertPanel uses NSBeginAlertSheet. Looking at the documentation for NSBeginAlertSheet you can see that there are more parameters after msg (specified by the ...).

This tells us that title is just a string literally displayed but the message can have format parameters the same way that [NSString stringWithFormat:] does.

The way that a string specifies that there is going to be a parameter is by using a % character i.e. %i means 'put an integer here', %@ means 'put an object's description here'. You've just put a % by itself, which gets things very confused!

The double %% means this percent isn't me telling you that I want you to put anything special in there, I really just want the % please.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文