views:

15

answers:

1

playerOneScore is a int, How can I pass it to use a label to display the score? This code just prints %i...

-(void)updateScoreLabels{
        playerOneScoreLabel.text = @"%i",playerOneScore;
        playerTwoScoreLabel.text = @"%i",playerTwoScore;
        playerThreeScoreLabel.text = @"%i",playerThreeScore;
        playerFourScoreLabel.text = @"%i",playerFourScore;
    }
+1  A: 

You need to initialize string using convenience constructor:

playerOneScoreLabel.text = [NSString stringWithFormat:@"%i",playerOneScore];
...

What you actually have in your code is comma operator - it evaluates its 1st parameter (that is assigns @"%i" string to a label), then evaluates and returns 2nd parameter - playerOneScore.

Vladimir