Integer to NSString

Discussion in 'iOS Programming' started by Programmer, Oct 1, 2009.

  1. Programmer macrumors member

    Programmer

    Joined:
    Jun 16, 2009
    #1
    I have a an NSInteger in my application called score and i want to show the score integer in a UILabel. I Tried the formatWithObject method but for some reason it did't work.

    ScoreLabel.text = [NSString formatWithObject:mad:"%d", (int) score];

    Any help is appreciated.
     
  2. Darkroom Guest

    Darkroom

    Joined:
    Dec 15, 2006
    Location:
    Montréal, Canada
    #2
    Code:
    NSString *scoreString = [[NSString alloc] initWithFormat:@"%d", score];
    ScoreLabel.text = scoreString;
    [scoreString release];
    [COLOR="Green"]//you can also use %i conversions for integers[/COLOR]
    
     
  3. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #3
    That's because NSString has no formatWithObject: class method. In fact, nothing does. You're gonna want to avoid making up your own API methods and stick to the ones provided to you.
     
  4. Programmer thread starter macrumors member

    Programmer

    Joined:
    Jun 16, 2009
  5. drf1229 macrumors regular

    drf1229

    Joined:
    Jun 22, 2009
    #5
    Try this:

    textbox.text=[NSString stringWithFormat:mad:"%i", integervariable];
     

Share This Page