在 NSRunAlertPanel 中显示 % 时遇到问题
我正在开发一个桌面应用程序,我想使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
试试这个:
为什么?
NSRunAlertPanel
使用NSBeginAlertSheet
。查看 NSBeginAlertSheet的文档可以看到msg后面还有更多的参数(由...
指定)。这告诉我们,标题只是一个字面显示的字符串,但消息可以像
[NSString stringWithFormat:]
一样具有格式参数。字符串指定参数的方式是使用 % 字符,即 %i 表示“在此处放置一个整数”,%@ 表示“在此处放置对象的描述” '。你只是单独加上了一个%,这让事情变得非常混乱!
双 %% 意味着这个百分比不是我告诉你我希望你在里面放一些特别的东西,我真的只是想要 %。
Try this :
Why?
NSRunAlertPanel
usesNSBeginAlertSheet
. 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.