无法在 EKEvent 中编程开始日期
我使用以下代码来获取新 EKEvent 的开始日期:
event.startDate = [NSString stringWithFormat:@"%@", dateField.text];
event.endDate = [[NSDate alloc] initWithTimeInterval:10 sinceDate:event.startDate];
文本来自文本框,出于示例目的,我输入“2011/09/16”。
它出现了这个错误:
2011-09-15 20:53:20.541 iDHSB[205:707] -[NSCFString timeIntervalSinceReferenceDate]: unrecognized selector sent to instance
0x10ef30
2011-09-15 20:53:20.566 iDHSB[205:707] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-
[NSCFString timeIntervalSinceReferenceDate]: unrecognized selector sent to instance 0x10ef30'
*** Call stack at first throw:
(
0 CoreFoundation 0x3624c64f __exceptionPreprocess + 114
1 libobjc.A.dylib 0x36f9fc5d objc_exception_throw + 24
2 CoreFoundation 0x362501bf -[NSObject(NSObject) doesNotRecognizeSelector:] + 102
3 CoreFoundation 0x3624f649 ___forwarding___ + 508
4 CoreFoundation 0x361c6180 _CF_forwarding_prep_0 + 48
5 EventKit 0x31b7bc4d -[EKEvent setStartDate:] + 168
6 iDHSB 0x00007b8b -[iDHSB_MobileAppDelegate alertView:clickedButtonAtIndex:] + 690
7 UIKit 0x32a63cf3 -[UIAlertView(Private) _buttonClicked:] + 230
8 CoreFoundation 0x361bc571 -[NSObject(NSObject) performSelector:withObject:withObject:] + 24
9 UIKit 0x32955ec9 -[UIApplication sendAction:to:from:forEvent:] + 84
10 UIKit 0x32955e69 -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 32
11 UIKit 0x32955e3b -[UIControl sendAction:to:forEvent:] + 38
12 UIKit 0x32955b8d -[UIControl(Internal) _sendActionsForEvents:withEvent:] + 356
13 UIKit 0x32956423 -[UIControl touchesEnded:withEvent:] + 342
14 UIKit 0x32954bf5 -[UIWindow _sendTouchesForEvent:] + 368
15 UIKit 0x3295456f -[UIWindow sendEvent:] + 262
16 UIKit 0x3293d313 -[UIApplication sendEvent:] + 298
17 UIKit 0x3293cc53 _UIApplicationHandleEvent + 5090
18 GraphicsServices 0x32813e77 PurpleEventCallback + 666
19 CoreFoundation 0x36223a97 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 26
20 CoreFoundation 0x3622583f __CFRunLoopDoSource1 + 166
21 CoreFoundation 0x3622660d __CFRunLoopRun + 520
22 CoreFoundation 0x361b6ec3 CFRunLoopRunSpecific + 230
23 CoreFoundation 0x361b6dcb CFRunLoopRunInMode + 58
24 GraphicsServices 0x3281341f GSEventRunModal + 114
25 GraphicsServices 0x328134cb GSEventRun + 62
26 UIKit 0x32967d69 -[UIApplication _run] + 404
27 UIKit 0x32965807 UIApplicationMain + 670
28 iDHSB 0x00002cfd main + 48
29 iDHSB 0x00002cc8 start + 40
)
terminate called after throwing an instance of 'NSException'
(gdb)
这是为什么?
I have used the following code to get a start date for my new EKEvent:
event.startDate = [NSString stringWithFormat:@"%@", dateField.text];
event.endDate = [[NSDate alloc] initWithTimeInterval:10 sinceDate:event.startDate];
The text is from a textbox and for example purposes, I put "2011/09/16".
It came up with this error:
2011-09-15 20:53:20.541 iDHSB[205:707] -[NSCFString timeIntervalSinceReferenceDate]: unrecognized selector sent to instance
0x10ef30
2011-09-15 20:53:20.566 iDHSB[205:707] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-
[NSCFString timeIntervalSinceReferenceDate]: unrecognized selector sent to instance 0x10ef30'
*** Call stack at first throw:
(
0 CoreFoundation 0x3624c64f __exceptionPreprocess + 114
1 libobjc.A.dylib 0x36f9fc5d objc_exception_throw + 24
2 CoreFoundation 0x362501bf -[NSObject(NSObject) doesNotRecognizeSelector:] + 102
3 CoreFoundation 0x3624f649 ___forwarding___ + 508
4 CoreFoundation 0x361c6180 _CF_forwarding_prep_0 + 48
5 EventKit 0x31b7bc4d -[EKEvent setStartDate:] + 168
6 iDHSB 0x00007b8b -[iDHSB_MobileAppDelegate alertView:clickedButtonAtIndex:] + 690
7 UIKit 0x32a63cf3 -[UIAlertView(Private) _buttonClicked:] + 230
8 CoreFoundation 0x361bc571 -[NSObject(NSObject) performSelector:withObject:withObject:] + 24
9 UIKit 0x32955ec9 -[UIApplication sendAction:to:from:forEvent:] + 84
10 UIKit 0x32955e69 -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 32
11 UIKit 0x32955e3b -[UIControl sendAction:to:forEvent:] + 38
12 UIKit 0x32955b8d -[UIControl(Internal) _sendActionsForEvents:withEvent:] + 356
13 UIKit 0x32956423 -[UIControl touchesEnded:withEvent:] + 342
14 UIKit 0x32954bf5 -[UIWindow _sendTouchesForEvent:] + 368
15 UIKit 0x3295456f -[UIWindow sendEvent:] + 262
16 UIKit 0x3293d313 -[UIApplication sendEvent:] + 298
17 UIKit 0x3293cc53 _UIApplicationHandleEvent + 5090
18 GraphicsServices 0x32813e77 PurpleEventCallback + 666
19 CoreFoundation 0x36223a97 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 26
20 CoreFoundation 0x3622583f __CFRunLoopDoSource1 + 166
21 CoreFoundation 0x3622660d __CFRunLoopRun + 520
22 CoreFoundation 0x361b6ec3 CFRunLoopRunSpecific + 230
23 CoreFoundation 0x361b6dcb CFRunLoopRunInMode + 58
24 GraphicsServices 0x3281341f GSEventRunModal + 114
25 GraphicsServices 0x328134cb GSEventRun + 62
26 UIKit 0x32967d69 -[UIApplication _run] + 404
27 UIKit 0x32965807 UIApplicationMain + 670
28 iDHSB 0x00002cfd main + 48
29 iDHSB 0x00002cc8 start + 40
)
terminate called after throwing an instance of 'NSException'
(gdb)
Why is this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
EKEvent 的 startDate 属性被声明为 NSDate,但您向其传递 NSString。您需要先将字符串解析为 NSDate,然后设置事件日期:
EKEvent's startDate property is declared as an NSDate but you are passing it an NSString. You need to parse the string into a NSDate first and then set the event date:
@Tim Dean 是在正确的轨道上,但该初始化程序仅用于返回 OS 10.0 样式的日期格式化程序,甚至在 iOS 上不受支持。
@Tim Dean was on the right track, but that initializer is only used to return OS 10.0 style date formatters and isn't even supported on iOS.