ok,所以这个问题有点奇怪,因为NSLog我有权在应该打印出文本的代码行前面返回正确的值。标签没有在setter中更新
下面的代码:
-(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一致。
感谢您的帮助!
欢呼声, 马特
你能否证实'currentDate'不是'nil'打电话时'的setText:' – 2012-01-02 20:52:53
还有什么是你想达到这个'[自我setCurrentDate:self.currentDate]'?我认为只需要调用一个方法来设置文本值不会将相同的对象重新分配给自己,并且副作用可以设置日期,这会更有意义。 – 2012-01-02 20:58:36
是的...它是NULL ...但1)我不明白为什么,因为它不是标签本身? 2)它第一次工作,为什么不在其他时间呢? =/ – 2012-01-02 21:24:17