View Full Version : Problems Formatting String and Assigning to Label

Nov 13, 2009, 09:38 PM
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!

Nov 13, 2009, 09:40 PM
Wow, just found my problem, was releasing formatter too early. If any moderator could delete this thread that would be great. Sorry about that.