我试图强迫用户使用日期选择器选择未来的日期。我显然使用了 compare: 方法,但是,当我执行以下代码时,即使它与 [NSDate date] 的日期相同,它也会告诉执行 if 语句。这是我的代码:
if ([datePicker.date compare:[NSDate date]] == NSOrderedAscending) // If the picked date is earlier than today
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Hmm, this date is earlier than today"
message:@"The date you've selected is earlier than today's date, please pick another"
delegate:nil
cancelButtonTitle:@"Okay, I'll pick another"
otherButtonTitles:nil];
// Show the alert
[alert show];
// Release the alert
[alert release];
}