Problems Formatting String and Assigning to Label

Discussion in 'iOS Programming' started by Stunner, Nov 13, 2009.

  1. macrumors newbie

    Sep 14, 2009
    Ey guys, having some problems with formatting a string and passing it to a label. Here is my code:

    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setDateFormat:@"HH:mm:ss"];
    NSLog(@"%@", [formatter stringFromDate:d]); //outputs everything properly
    [formatter release];
    NSString *minsToGoLabelTextStr = [[NSString alloc] initWithString:[formatter stringFromDate:d]];
    minsToGo.text = minsToGoLabelTextStr;//problem here
    [minsToGoLabelText release];
    [minsToGoLabelTextStr release];
    The NSLog that I have noted in the code above works perfectly, but I am having trouble assigning it to the minsToGo label. I believe I am passing in a string but have no idea why its not working. Even this doesn't work:
    minsToGo.text = [formatter stringFromDate:d];
    I bet it is something really stupid or simple that I am overlooking, if so I am sorry, but I am just not seeing the problem. Any help appreciated. Thanks!
  2. thread starter macrumors newbie

    Sep 14, 2009
    Wow, just found my problem, was releasing formatter too early. If any moderator could delete this thread that would be great. Sorry about that.

Share This Page