標籤不顯示所需的值,但nslog
顯示應該由標籤顯示的正確值。標籤顯示一個充滿數字的大數字。我做錯了什麼?,相關代碼如下所示。顯示錯誤值的標籤,而NSLog在SpriteKit中顯示正確的值
它的外觀在頂部...
@implementation ORPlayerResults
{
SKLabelNode *numberOfPointsLabel;
NSInteger newPoints;
NSString *addingNewPointNumberStored;
}
在didMoveToView
...
-(void)didMoveToView:(SKView *)view
{
// adding the label
[self addChild:[self pointsTotalLabel]];
}
有關標籤
-(SKLabelNode *)pointsTotalLabel
{
numberOfPointsLabel = [[SKLabelNode alloc] initWithFontNamed:@"Arial"];
numberOfPointsLabel.text = @"Points Achieved: 0";
numberOfPointsLabel.fontSize = 35;
numberOfPointsLabel.fontColor = [SKColor whiteColor];
numberOfPointsLabel.position = CGPointMake((self.size.width * 0.5)-200, self.size.height - 200);
numberOfPointsLabel.horizontalAlignmentMode = SKLabelHorizontalAlignmentModeLeft;
return numberOfPointsLabel;
}
下面的文本標籤沒有顯示信息正確的值,而是顯示一個錯誤的大數字滿數字。 nslog
顯示我想要的結果。
-(void)pointsAchieved
{
newPoints = [[NSUserDefaults standardUserDefaults] integerForKey:kORNewPoints];
addingNewPointNumberStored = [NSString stringWithFormat:@"%li", (long)newPoints];
numberOfPointsLabel.text = [NSString stringWithFormat:@"Points Achieved: %ld", (long)addingNewPointNumberStored];
NSLog(@"Points accumulated is: %@", addingNewPointNumberStored);
}
我認爲使用dispatch_get_main_queue()可以解決這個問題。 – Roecrew
@Roecrew代碼的外觀如何?我從來沒有使用dispatch_get_main_queue()。 –