首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >UIDatePicker "copyWithZone“错误

UIDatePicker "copyWithZone“错误
EN

Stack Overflow用户
提问于 2014-09-12 10:02:44
回答 1查看 175关注 0票数 0

这是用于调度警报的以下代码,我收到了以下错误。在我试图将当前的日期与采摘者进行比较之前,它一直运行得很好:

代码语言:javascript
复制
[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。我的调试能力很差,还没有找到解决方案。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-09-12 10:15:36

我相信你的问题就在这条线上。

代码语言:javascript
复制
localNotification.fireDate = datePicker;

您没有提供上面定义“datePicker”的代码,但我的猜测是,您的意思是键入"pickerDate“而不是"datePicker",这不符合NSCopying协议(而且无论如何也不是NSDate ),这就是抛出错误的原因。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/25805706

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档