好的,所以这个问题有点奇怪,因为我在应该打印出文本的代码行前面的 NSLog 返回了正确的值。
这是代码:
-(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
}
因此,当应用程序首次启动时,一切都很好。标签更新和一切。当我按下一个基本上抓住新日期的按钮时,问题就出现了。在这个过程中,它运行这个:
//need to reload the "on day" label now
[self setCurrentDate:self.currentDate];
//and the "days left" label
[self setDaysLeft:self.daysLeft];
同样,我认为这一切都应该是正确的,因为 NSLog 正在返回正确的内容。我认为问题出在我展示的第一个代码块中的最后一行......带有 setText 的行。
感谢你的帮助!
干杯,马特