这是用于调度警报的以下代码,我收到了以下错误。在我试图将当前的日期与采摘者进行比较之前,它一直运行得很好:
[self.eventText resignFirstResponder];
NSCalendar *calendar = [NSCalendar autoupdatingCurrentCalendar];
//Get the current date
NSDate *pickerDate = [self.datePicker date];
//Unable to set notification for same day
[datePicker setMinimumDate:[NSDate date]];
//Break the date up into components
NSDateComponents *dateComponents = [calendar components: (NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit) fromDate:pickerDate];
NSDateComponents *timeComponents = [calendar components: (NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit) fromDate:pickerDate];
// Schedule the notification
UILocalNotification* localNotification = [[UILocalNotification alloc] init];
localNotification.fireDate = datePicker;
localNotification.alertBody = self.eventText.text;
localNotification.alertAction = @"Show me the item";
localNotification.timeZone = [NSTimeZone systemTimeZone];
localNotification.applicationIconBadgeNumber = [[UIApplication sharedApplication] applicationIconBadgeNumber] + 1;
NSDictionary *infoDict = [NSDictionary dictionaryWithObjectsAndKeys:@"Object 1", @"Key 1", @"Object 2", @"Key 2", nil];
localNotification.userInfo = infoDict;
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
// Request to reload table view data
[[NSNotificationCenter defaultCenter] postNotificationName:@"reloadData" object:self];
eventText.text = nil;
[self dismissViewControllerAnimated:YES completion:nil];接收到以下错误:由于异常NSInvalidArgumentException终止应用程序,原因:-[UIDatePicker copyWithZone:]: unrecognized selector sent to instance 0x10ba853f0。我的调试能力很差,还没有找到解决方案。
发布于 2014-09-12 10:15:36
我相信你的问题就在这条线上。
localNotification.fireDate = datePicker;您没有提供上面定义“datePicker”的代码,但我的猜测是,您的意思是键入"pickerDate“而不是"datePicker",这不符合NSCopying协议(而且无论如何也不是NSDate ),这就是抛出错误的原因。
https://stackoverflow.com/questions/25805706
复制相似问题