IOS6上的NSDateComponents无法正常工作?
我有一个简单的程序与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)
第一轮是两个相等的date。 在第二次运行中,我已经改变了select器上的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);
感谢您的帮助!
我已经replace了
NSDateComponents *comps = [gregorian components:NSMonthCalendarUnit fromDate:startDate toDate:endDate options:0];
同
NSInteger months = [[[NSCalendar currentCalendar] components: NSMonthCalendarUnit fromDate: startDate toDate: endDate options: 0] month];
现在它正在工作:)。