%s in button name...

Discussion in 'iPhone/iPad Programming' started by ArtOfWarfare, Aug 22, 2008.

  1. macrumors 603

    ArtOfWarfare

    Joined:
    Nov 26, 2007
    #1
    I have this:

    Code:
    [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?
     
  2. macrumors 65816

    Sbrocket

    Joined:
    Jun 3, 2007
    Location:
    /dev/null
    #2
    That syntax can be a little flakey. I'm not quite sure what its proper use is, anyway. Use stringWithFormat: explicitly.

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

    Joined:
    May 24, 2003
    #3
    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 %@.
     

Share This Page