Cocoa touch Cocoa Touch-int作为字符串格式
PlayerScore是一个int,如何传递它以使用标签显示分数?此代码只打印%iCocoa touch Cocoa Touch-int作为字符串格式,cocoa-touch,integer,Cocoa Touch,Integer,PlayerScore是一个int,如何传递它以使用标签显示分数?此代码只打印%i -(void)updateScoreLabels{ playerOneScoreLabel.text = @"%i",playerOneScore; playerTwoScoreLabel.text = @"%i",playerTwoScore; playerThreeScoreLabel.text = @"%i",playerThreeScore;
-(void)updateScoreLabels{
playerOneScoreLabel.text = @"%i",playerOneScore;
playerTwoScoreLabel.text = @"%i",playerTwoScore;
playerThreeScoreLabel.text = @"%i",playerThreeScore;
playerFourScoreLabel.text = @"%i",playerFourScore;
}
您需要使用方便的构造函数初始化字符串:
playerOneScoreLabel.text = [NSString stringWithFormat:@"%i",playerOneScore];
...
代码中实际包含的是-它计算其第一个参数(即为标签分配@“%i”字符串),然后计算并返回第二个参数-playerScore 您需要使用便利构造函数初始化字符串:
playerOneScoreLabel.text = [NSString stringWithFormat:@"%i",playerOneScore];
...
代码中实际包含的是-它计算其第一个参数(即为标签分配@“%i”字符串),然后计算并返回第二个参数-playerScore