【问题标题】:Comparing NSDate and UIDatePicker ERROR比较 NSDate 和 UIDatePicker 错误
【发布时间】:2023-04-03 13:26:01
【问题描述】:

试图形成一个 if 语句,将左侧的当前日期与右侧的 UIDatePicker 中选择的日期进行比较,我认为这是我由 Stack Overflow 用户给出的正确代码,他们不应该能够执行此操作,他们不能,但我需要创建一个弹出窗口,告诉他们为什么不这样做:

  //Get the current date
  NSDate *pickerDate = [self.datePicker date];

  //Unable to set notification for same day
  //[datePicker setMinimumDate:[NSDate date]];

  self.datePicker.date  = [NSDate date];
  if ([pickerDate compare:datePicker] == NSOrderedAscending) {

    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Something wasn't right." message:@"That did not work and your alarm was not set." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];

    [alert show];
}

我在执行此操作时收到以下错误:

由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“-[UIDatePicker timeIntervalSinceReferenceDate]:无法识别的选择器发送到实例 0x10b9373a0”

【问题讨论】:

    标签: ios objective-c uilocalnotification


    【解决方案1】:

    仔细检查您对compare: 方法的调用。您正在与日期选择器而不是日期选择器的日期进行比较。

    你想要:

    if ([pickerDate compare:datePicker.date] == NSOrderedAscending) {
    

    【讨论】:

    • 非常感谢您的快速响应,这是一个新错误:由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:'-[UIDatePicker copyWithZone:]:无法识别的选择器已发送到实例 0x10ba86c80'
    • 这是一个全新的问题。关闭此问题并在需要时向另一个人询问新问题。请务必指出导致新问题的实际代码。但首先做一些调试。如果需要,请参阅raywenderlich.com/10209/my-app-crashed-now-what-part-1
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-05-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多