ok so this problem is kinda weird because the NSLog I have right in front of the line of code that should be printing out the text is returning the correct value.
Here’s the code:
-(void)setCurrentDate:(UILabel *)currentDate
{
NSInteger onDay = 1; //because if it's today, you are on day one, not zero... no such thing as a day zero
//get the nubmer of days left
if( [[NSUserDefaults standardUserDefaults] objectForKey:@"StartDate"] ){ //if there is something at the userdefaults
onDay = [self daysToDate:[NSDate date]];
}//otherwise, onDay will just be one
self.theCurrentNumberOfDaysSinceStart = onDay;
NSLog(@"On day: %d", onDay); //this is returning the correct values....
//print it out on the label
[currentDate setText:[NSString stringWithFormat:@"On day: %d", onDay]];//echoes out the current day number
}
So when the app first launches, everything is fine. The label updates and everything. The problem arises when I hit a button that basically grabs a new date. In the process, it runs this:
//need to reload the "on day" label now
[self setCurrentDate:self.currentDate];
//and the "days left" label
[self setDaysLeft:self.daysLeft];
Again, I’m thinking this should all be correct because the NSLog is returning the correct stuff. I’m thinking that the problem is with the last line in the first block of code I showed… the line with the setText.
thanks for all your help!
cheers,
Matt
If you used a nib
When the nib loads and establishes all of it connections it… (From the Resource Programming guide)
Therefore the nib will load and call
setCurrentDate:passing in the unarchivedUILabelas the parameterIn your method you configure the
UILabelusing the local reference passed into the methodYou at no point actually store a reference to this
UILabelin an ivar, so technically you have leaked the label and as you have not set the ivarcurrentDateit will be initialised tonil. This is the danger of overriding a setter with an incorrect implementation.At some point in your method you should be setting your ivar to the passed in variable. A normal setter would look like this
But
In your example I would not worry about this at all I would instead change this
to something like
The implementation would look something like: