在UILabel上设置文本会导致我的应用程序崩溃

Xco*_*der 1 iphone objective-c nsstring uilabel ios

所以我设置了我的UILabel,但是当我将游戏循环中的文本设置为一个得分的字符串(因此每次循环都重置了Text)时,我的应用程序崩溃了.

这是我得到的错误:

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];
Run Code Online (Sandbox Code Playgroud)

谢谢!

小智 5

您是否正在从主队列中更新标签?我发生了这些崩溃,直到我在主队列上发送了更新.

dispatch_async(dispatch_get_main_queue(), ^{
    self.lblSyncProgress.text = @"Some string";
});
Run Code Online (Sandbox Code Playgroud)