【发布时间】:2011-06-16 18:02:17
【问题描述】:
我不确定,但有时我的 if 语句会失败,并在不应该出现的情况下显示错误的内容 有什么想法吗?
-(void)updateLabel{
if (today > Date) {
[only setHidden:YES];
[untilRelease setHidden:YES];
[theLabel setText:@"IS OUT"];
} else {
NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
int units = NSMonthCalendarUnit | NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit;
NSDateComponents *components = [calendar components:units fromDate:[NSDate date] toDate:Date options:0];
[theLabel setText:[NSString stringWithFormat:@"%d %@, %d %@ \n %d %@, %d %@ %d %@", [components month], @"Months", [components day], @"Days", [components hour], @"Hours", [components minute], @"Minutes and", [components second], @"Seconds"]];
}}
我已将今天定义为 [NSDate date] 并且 Date 是一个纪元数。
任何帮助都会很棒
【问题讨论】:
-
只是一个疯狂的想法,但请检查“今天”是否未发布。将“今天”变量替换为 [NSDate 日期]——每次获取一个新变量——看看是否有效。
-
是的...这样做...奇怪的是有时它认为 NSDate 日期已过 Date 而不是:'(
-
我的
apple > orange声明有时不正确......
标签: ios xcode calendar if-statement nsdate