为什么我的UILabel被解除分配?

时间:2015-01-12 22:13:42

标签: objective-c uilabel automatic-ref-counting nszombie cfstring

我试图追查崩溃的来源。我已经将应用程序分析为寻找僵尸,它似乎与更新我的UILabel中的文本有关。我不认为我正在设置文本值不正确。这看起来不错吗?

enter image description here

这是我设置UILabels文本的地方。

- (void) updateTimecodeDisplay
{
    VarController *sharedController = [VarController sharedController];

    int time0 = sharedController.timeCode0Property;
    int time1 = sharedController.timeCode1Property;
    int time2 = sharedController.timeCode2Property;
    int time3 = sharedController.timeCode3Property;
    int time4 = sharedController.timeCode4Property;
    int time5 = sharedController.timeCode5Property;
    int time6 = sharedController.timeCode6Property;
    int time7 = sharedController.timeCode7Property;
    int time8 = sharedController.timeCode8Property;
    int time9 = sharedController.timeCode9Property;


    if (time0 != 16)
    {
        [timeCodeLabel0 setText:[NSString stringWithFormat:@"%d", time0]];
    }
    else {
        [timeCodeLabel0 setText:[NSString stringWithFormat:@""]];
    }
    if (time1 != 16)
    {
       [timeCodeLabel1 setText:[NSString stringWithFormat:@"%d", time1]];
    }
    else {
        [timeCodeLabel1 setText:[NSString stringWithFormat:@""]];
    }
    if (time2 != 16)
    {
        [timeCodeLabel2 setText:[NSString stringWithFormat:@"%d", time2]];
    }
    else {
        [timeCodeLabel2 setText:[NSString stringWithFormat:@""]];
    }
    if (time3 != 16)
    {
        [timeCodeLabel3 setText:[NSString stringWithFormat:@"%d", time3]];
    }
    else {
        [timeCodeLabel3 setText:[NSString stringWithFormat:@""]];
    }
    if (time4 != 16)
    {
        [timeCodeLabel4 setText:[NSString stringWithFormat:@"%d", time4]];
    }
    else {
        [timeCodeLabel4 setText:[NSString stringWithFormat:@""]];
    }
    if (time5 != 16)
    {
        [timeCodeLabel5 setText:[NSString stringWithFormat:@"%d", time5]];
    }
    else {
        [timeCodeLabel5 setText:[NSString stringWithFormat:@""]];
    }
    if (time6 != 16)
    {
        [timeCodeLabel6 setText:[NSString stringWithFormat:@"%d", time6]];
    }
    else {
        [timeCodeLabel6 setText:[NSString stringWithFormat:@""]];
    }
    if (time7 != 16)
    {
        [timeCodeLabel7 setText:[NSString stringWithFormat:@"%d", time7]];
    }
    else {
        [timeCodeLabel7 setText:[NSString stringWithFormat:@""]];
    } 
    if (time8 != 16)
    {
        [timeCodeLabel8 setText:[NSString stringWithFormat:@"%d", time8]];
    }
    else {
        [timeCodeLabel8 setText:[NSString stringWithFormat:@""]];
    }
    if (time9 != 16)
    {
        [timeCodeLabel9 setText:[NSString stringWithFormat:@"%d", time9]];
    }
    else {
        [timeCodeLabel9 setText:[NSString stringWithFormat:@""]];
    }
}

UILabels正在头文件中声明如下:

我现在添加了UILabel的属性,如下所示,并在.m文件中合成它们。仍然得到完全相同的问题。

@property (weak) IBOutlet UILabel *timeCodeLabel0;
@property (weak) IBOutlet UILabel *timeCodeLabel1;
@property (weak) IBOutlet UILabel *timeCodeLabel2;
@property (weak) IBOutlet UILabel *timeCodeLabel3;
@property (weak) IBOutlet UILabel *timeCodeLabel4;
@property (weak) IBOutlet UILabel *timeCodeLabel5;
@property (weak) IBOutlet UILabel *timeCodeLabel6;
@property (weak) IBOutlet UILabel *timeCodeLabel7;
@property (weak) IBOutlet UILabel *timeCodeLabel8;
@property (weak) IBOutlet UILabel *timeCodeLabel9;

1 个答案:

答案 0 :(得分:1)

我想你应该查看这篇文章,谈谈“ - >”操作者:Dot (".") operator and arrow ("->") operator use in C vs. Objective-C

这意味着您不应该使用“ - >”访问财产。因为底层很多。希望这会有所帮助。

IBOutlet应该使用@weak