Estoy tratando de obligar a un usuario a seleccionar una fecha en el futuro con un selector de fecha. Obviamente, utilicé el método compare: sin embargo, cuando hago el siguiente código, incluso si es la misma fecha que [NSDate date], le dice a la persona que ejecuta la instrucción if. Aquí está mi código:Comparando un NSDate con [NSDate date]
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];
}
¿Ha intentado utilizar 'laterDate:' (o 'previousDate:') para hacer la comparación? – gerry3
Qué sucede si NSLogia la fecha solo para ver si tiene el valor correcto. –