0
这是用于安排警报的以下代码,并且我收到以下错误。它已经完美的工作,直到我试图为当前日期比较捡拾工具:UIDatePicker“copyWithZone”错误
[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:18:19