1

所以我已经设置了我的 UILabel,但是当我将我的游戏循环中的文本设置为一个作为分数的字符串时(所以文本在每个循环中被重置)我的应用程序崩溃了。

这是我得到的错误:

0x15560b0: cmpl (%eax), %ecx 线程 1

断点是这样说的:

EXC_BAD_ACCESS(代码=1,地址=0x67b30064

这是我设置 UILabel 的方式(在我的 init 方法中):

//SET UP THE SCORE LABEL HERE
scoreLabel = [[UILabel alloc] init];
scoreString = [NSString stringWithFormat:@"%d", score];
[scoreLabel setFont: [UIFont fontWithName: @"TimesNewRoman" size: 10.0f]];
[scoreLabel setFrame: CGRectMake(262, 250, 100, 40)];
[scoreLabel setBackgroundColor:[UIColor clearColor]];
[scoreLabel setTextColor: [UIColor clearColor]];
[scoreLabel setTextColor: [UIColor whiteColor]];
scoreLabel.transform = CGAffineTransformMakeRotation(89.53);
[self addSubview: scoreLabel];
//[scoreLabel setText: scoreString];

谢谢你!

4

3 回答 3

5

您是否在主队列之外进行标签更新?在我将更新发送到主队列之前,我遇到了这些崩溃。

dispatch_async(dispatch_get_main_queue(), ^{
    self.lblSyncProgress.text = @"Some string";
});
于 2014-01-14T13:05:15.097 回答
2
//in your .h file
UILabel *scoreLabel;
NSString *scoreString;


//in your .m file    
//SET UP THE SCORE LABEL HERE 
scoreLabel = [[UILabel alloc] init];
 [scoreLabel setFont: [UIFont fontWithName: @"TimesNewRoman" size: 10.0f]];
 [scoreLabel setFrame: CGRectMake(262, 250, 100, 40)];
 [scoreLabel setBackgroundColor:[UIColor clearColor]];
 [scoreLabel setTextColor: [UIColor clearColor]];
 [scoreLabel setTextColor: [UIColor whiteColor]];
 scoreLabel.transform = CGAffineTransformMakeRotation(89.53);
 [self addSubview: scoreLabel]; 


//In your update method
 scoreString = [NSString stringWithFormat:@"%d", score];
scoreLabel.text = scoreString;
于 2012-08-18T21:22:27.150 回答
-1

我在你的代码中注意到你有

scoreString = [NSString stringWithFormat:@"%d", score];

确保“分数”是一个字符。如果不是看看这个

于 2012-08-18T21:23:59.740 回答