所以我设置了我的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];
谢谢!
答案 0 :(得分:5)
您是否正在从主队列中更新标签?在我在主队列上发送更新之前,我遇到了这些崩溃。
dispatch_async(dispatch_get_main_queue(), ^{
self.lblSyncProgress.text = @"Some string";
});
答案 1 :(得分: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;
答案 2 :(得分:-1)