PDA

View Full Version : %s in button name...




ArtOfWarfare
Aug 22, 2008, 07:58 PM
I have this:

[secondRedButton setTitle: (@"%s Stole It!!", secondTeamName.text) forState: UIControlStateNormal];

It should make the button say "(Name of second team) Stole It!"... instead it just makes the button say "(Name of second team)". Any idea why?



Sbrocket
Aug 22, 2008, 11:09 PM
I have this:

[secondRedButton setTitle: (@"%s Stole It!!", secondTeamName.text) forState: UIControlStateNormal];

It should make the button say "(Name of second team) Stole It!"... instead it just makes the button say "(Name of second team)". Any idea why?

That syntax can be a little flakey. I'm not quite sure what its proper use is, anyway. Use stringWithFormat: explicitly.

[secondRedButton setTitle:[NSString stringWithFormat:@"%s Stole It!!", secondTeamName.text] forState: UIControlStateNormal];

grimjim
Aug 23, 2008, 08:22 AM
I thought that %s was the format specifier for a C-type character array. I'm assuming that the text property of secondTeam actually returns an NSString, in which case you might have more luck using %@.