Reputation: 1028
I have a sting that is equal to a text field that i want to insert inside of a UIAlertView.
NSString *finalScore = [[NSString alloc] initWithFormat:[counter2 text]];
UIAlertView *myAlertView = [[UIAlertView alloc]
initWithTitle:finalScore
message:@"You scored X points"
delegate:self
cancelButtonTitle:nil
otherButtonTitles:@"OK", nil];
[myAlertView show];
[myAlertView release];
I want to replace"X" with the score from the string "finalScore"
I know how to have it just with the score, you would simple just enter the strings name without quotes under the message section, but i want the the text there too along with the string.
Thanks a bunch, Chase
Upvotes: 1
Views: 3315
Reputation: 28600
Replace your message:
parameter with:
message:[NSString stringWithFormat:@"You scored %@ points", finalScore]
Also, note that your original code for finalScore
uses string formatting without any arguments, which is either a no-op or unsafe (if it contains a %
symbol). You are also leaking your finalScore
object.
Upvotes: 4
Reputation: 35925
Try something like the following, and pass it as the message
variable to UIAlertView's initialization:
NSString* message = [NSString stringWithFormat:@"You scored %@ points",
[counter2 text]];
You might have to change some details about the formatting string depending on the type that comes out of [counter2 text]
, however, though the above should work in many of the cases you'll encounter.
Upvotes: 1
Reputation: 31280
Instead of:
@"You scored X points"
use:
[NSString stringWithFormat:@"You scored %@ points", finalScore]
Upvotes: 0