0

Im trying to track down the source of a crash. I've profiled the app to look for zombies and it appears to be related to updating the text in one of my UILabels. I don't think I am setting the text value improperly. Does this look right?

enter image description here

This is where I'm setting the text of the 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:@""]];
    }
}

The UILabels are being declared in the header file like this:

I've now added properties for the UILabels as hinted at below, and synthesized them in the .m file. Still getting the exact same issue though.

@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;
Luke
  • 11,426
  • 43
  • 60
  • 69
Youngin
  • 261
  • 4
  • 14
  • In the stack trace on the right, can you see which line in updateTimecodeDisplay it's being triggered on? Is updateTimecodeDisplay being called when the view is not rendered on the screen? – Bek Jan 12 '15 at 22:25
  • You've declared the UILabel's globally, not as the properties of a view controller? – Jon Shier Jan 12 '15 at 22:45
  • Please stop vandalising your own question, thanks. – Luke Jan 13 '15 at 21:13

1 Answers1

1

I think you should check out this post to talk about the "->" operator:Dot (".") operator and arrow ("->") operator use in C vs. Objective-C

It means that you are not supposed to use "->" to access property. Because there are many underlying layer. Hope this helps.

IBOutlet should be using @weak

Community
  • 1
  • 1
Lucas Huang
  • 3,998
  • 3
  • 20
  • 29
  • Can you post how you declare all your UILabel? More info could be helpful. – Lucas Huang Jan 12 '15 at 22:39
  • Profile said it's zombie. That might have other places that caused this problem which the problem is not in the code you posted. – Lucas Huang Jan 12 '15 at 22:40
  • IBOutlet should be used weak. Otherwise, it will have retain cycles. – Lucas Huang Jan 12 '15 at 23:20
  • The way you are referencing the UILabel is weird also. You can either access dot notation or instant variable. But you just referenced it by name. I think you might have other issues. Can you just try to debug it instead of running the Profile? I don't think you need to do that. – Lucas Huang Jan 13 '15 at 00:46