0

我有一个使用 IOS4 和 5 的简单程序。现在使用 IOS 6 我收到以下错误消息:

2012-10-05 11:08:16.386 app[1698:19d03] 2012-10-05 09:08:11 +0000
2012-10-05 11:08:18.072 app[1698:19d03] 2012-10-05 09:08:11 +0000
2012-10-05 11:08:19.273 app[1698:19d03] 2012-10-05 09:08:11 +0000
2012-10-05 11:08:19.274 app[1698:19d03] 2012-10-05 09:08:11 +0000
2012-10-05 11:08:19.275 app[1698:19d03] 0
2012-10-05 11:08:25.055 app[1698:19d03] 2011-10-05 09:08:11 +0000
2012-10-05 11:08:25.823 app[1698:19d03] (
"<UILongPressGestureRecognizer: 0xa167f60; state = Possible; view = <UITableViewCellContentView 0xa168000>; target= <(action=_longPressGestureRecognized:, target=<UIPickerTableViewWrapperCell 0xa168090>)>>")
2012-10-05 11:08:25.824 app[1698:19d03] 2012-10-05 09:08:11 +0000
2012-10-05 11:08:25.824 app[1698:19d03] -[__NSArrayI timeIntervalSinceReferenceDate]: unrecognized selector sent to instance 0x94ef5d0
2012-10-05 11:08:25.825 app[1698:19d03] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayI timeIntervalSinceReferenceDate]: unrecognized selector sent to instance 0x94ef5d0'
*** First throw call stack:
(0x1d16012 0x11fae7e 0x1da14bd 0x1d05bbc 0x1d0594e 0x1d25cd3 0xa092 0x120e705 0x145920 0x1458b8 0x206671 0x206bcf 0x205d38 0x17533f 0x175552 0x1533aa 0x144cf8 0x1f4fdf9 0x1f4fad0 0x1c8bbf5 0x1c8b962 0x1cbcbb6 0x1cbbf44 0x1cbbe1b 0x1f4e7e3 0x1f4e668 0x14265c 0x296d 0x28a5)

第一次运行是两个相等的日期。如您所见,在第二次运行中,我更改了选择器上的 fhDate ...

为了便于阅读,代码被简化了一点:

aiDate = [adoIgazPicker date];
NSLog(@"%@", aiDate);
fhDate = [forgHelyPicker date];
NSLog(@"%@", fhDate);
NSCalendar *gregorian = [[NSCalendar alloc]initWithCalendarIdentifier:NSGregorianCalendar];
NSDate *startDate = fhDate;
NSDate *endDate = aiDate;
NSLog(@"%@", startDate);
NSLog(@"%@", endDate);
NSDateComponents *comps = [gregorian components:NSMonthCalendarUnit fromDate:startDate toDate:endDate options:0]; //THIS LINE FAILS IF THE DATES ARE NOT THE SAME
int months = [comps month];
NSLog(@"%i", months);

谢谢您的帮助!

4

1 回答 1

0

我已经换了

NSDateComponents *comps = [gregorian components:NSMonthCalendarUnit fromDate:startDate toDate:endDate options:0];

NSInteger months = [[[NSCalendar currentCalendar] components: NSMonthCalendarUnit
                                                    fromDate: startDate
                                                      toDate: endDate
                                                     options: 0] month];

现在它正在工作:)。

于 2012-10-08T11:28:22.713 回答