Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Programmer

macrumors member
Original poster
Jun 16, 2009
79
0
In my application i have a score and a high score string. I set up a string the UIAlertViewBody NSString set up which sets the text in my UIAlertView message, it tells it to say "Your Score Was (scoreString) Your High Score Is (HighScoreS)". But when i run the application on my phone it just says "Your Score was" when the UIAlertView Pops up.

Here's the rest of the code.

Code:
NSString *scoreString = [[NSString alloc] initWithFormat:@"%d", score];
NSString *HighScoreS = [[NSString alloc] initWithFormat:@"%d", Highscoreint];
NSString *UIAlertViewBody = [NSString stringWithFormat:@"Your Score Was", [NSString stringWithFormat:scoreString], [NSString stringWithFormat:@"Your High Score Is"], [NSString stringWithFormat:HighScoreS]];

UIAlertView *YouWinHighScore = [[UIAlertView alloc] initWithTitle:@"Score" message:UIAlertViewBody delegate:self cancelButtonTitle:@"Close" otherButtonTitles:@"Challenge A Friend By Email", @"Challenge A Friend By Text", nil];
	[YouWinHighScore show];
	[YouWinHighScore release];
 
Code:
NSString *UIAlertViewBody = [NSString stringWithFormat:@"Your Score Was %@ Your High Score Is %@", scoreString, HighScoreS];
 
Why don't you simply do:

Code:
NSString *UIAlertViewBody = [NSString stringWithFormat:@"Your Score Was %d Your High Score Is %d", score, Highscoreint];

UIAlertView *YouWinHighScore = [[UIAlertView alloc] initWithTitle:@"Score" message:UIAlertViewBody delegate:self cancelButtonTitle:@"Close" otherButtonTitles:@"Challenge A Friend By Email", @"Challenge A Friend By Text", nil];
[YouWinHighScore show];
[YouWinHighScore release];

And for an internationalization you should use NSLocalizedString. That way you can later place the text in a .strings file and let it translate to other languages:
Code:
NSString *UIAlertViewBody = [NSString stringWithFormat:NSLocalizedString(@"Your Score Was %d Your High Score Is %d", @""), score, Highscoreint];

And in Localized.strings for english:
Code:
"Your Score Was %d Your High Score Is %d" = "Your Score Was %d Your High Score Is %d";

And in Localized.strings for german:
Code:
"Your Score Was %d Your High Score Is %d" = "Ihre Punktzahl war %d Ihre Punktzalh ist %d";
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.