0

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.

Zach Saucier
  • 24,871
  • 12
  • 85
  • 147
spd
  • 2,114
  • 1
  • 29
  • 54
  • Sorry users! This has been posted already. Please refer the link:http://stackoverflow.com/questions/1860609/displaying-percentage-using-nsstring It works fine. – spd Dec 21 '10 at 11:30
  • FYI : I've just edited my question to explain why it works in the title with a single % but in the message it needs %%. – deanWombourne Dec 21 '10 at 11:39

1 Answers1

0

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.

deanWombourne
  • 38,189
  • 13
  • 98
  • 110