Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 无效参数不满足:日期_Objective C_Nsdate_Nsdateformatter - Fatal编程技术网

Objective c 无效参数不满足:日期

Objective c 无效参数不满足:日期,objective-c,nsdate,nsdateformatter,Objective C,Nsdate,Nsdateformatter,我从Crashlytics收到一个问题。我打开了调试参数,所以我看到了有哪些参数 datePicker = [[UIDatePicker alloc] initWithFrame:CGRectMake(0, 40, 0, 0)]; NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; NSString *startTimeString = [MathFunctions minutesToTimeStrin

我从Crashlytics收到一个问题。我打开了调试参数,所以我看到了有哪些参数

datePicker = [[UIDatePicker alloc] initWithFrame:CGRectMake(0, 40, 0, 0)];
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    NSString *startTimeString = [MathFunctions minutesToTimeString:[appointment.start_time integerValue]];
    NSLog(@"Time: %@",startTimeString);
    NSLog(@"Date: %@", appointment.date);
    [dateFormatter setDateFormat:@"yyyyMMdd h:mm a"];
    [Crashlytics setObjectValue:[NSString stringWithFormat:@"%@ %@", appointment.date, startTimeString] forKey:@"ResAddDate"];
    NSString *dateTimeString = [NSString stringWithFormat:@"%@ %@", appointment.date, startTimeString];
    NSLog(@"Date String: %@", dateTimeString);
    datePicker.date = [dateFormatter dateFromString:dateTimeString];
来自crashlytics的crashlog显示日期格式正确

RESADDDATE:20120621凌晨12:00

崩溃发生在
datePicker.date=[dateFormatter dateFromString:dateTimeString]

如果日期格式存在且正确,为什么会崩溃

Crashlytics日志:

CoreFoundation  
__exceptionPreprocess + 162
1    libobjc.A.dylib    
objc_exception_throw + 32
2    CoreFoundation 
+[NSException raise:format:]
3    Foundation 
-[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 90
4    UIKit  
-[UIDatePickerView _updateBitsForDate:forced:andReload:animateIfNeeded:] + 146
5    UIKit  
-[UIDatePickerView _setDate:animated:forced:] + 348
6    UIKit  
-[UIDatePickerView setDate:animated:] + 30
7    UIKit  
-[UIDatePicker setDate:] + 36
8    MyApp   ReserveAddController.m line 283
-[ReserveAddController showDatePicker] + 283
9    MyApp   ReserveAddController.m line 179
-[ReserveAddController tableView:didSelectRowAtIndexPath:] + 179
10   UIKit  
-[UITableView _selectRowAtIndexPath:animated:scrollPosition:notifyDelegate:] + 944
11   UIKit  
-[UITableView _userSelectRowAtPendingSelectionIndexPath:] + 158
12
Foundation  
__NSFireDelayedPerform + 414
13   CoreFoundation 
__CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 14
14   CoreFoundation 
__CFRunLoopDoTimer + 364
15   CoreFoundation 
__CFRunLoopRun + 1206
16   CoreFoundation 
CFRunLoopRunSpecific + 300
17   CoreFoundation 
CFRunLoopRunInMode + 104
18   GraphicsServices   
GSEventRunModal + 136
19   UIKit  
UIApplicationMain + 1080
20   Appointment-Plus    main.m line 16
main + 16
21   Appointment-Plus

请注意,您可能会通过区域设置“”获得位。您需要设置NSDateFormatter的区域设置


使用US locale设置电话,然后将12/24设置设置为24。同时将手机设置为欧洲语言环境,然后将12/24设置设置为12。很可能其中一个或另一个或两个都会失败。

您能显示崩溃日志或跟踪吗?@MichaelFredrick我编辑了OPUIDatePicker的断言失败。这是一个相当不健壮的API,所以这并不令人惊讶。最好打印出传递给UIDatePicker的实际NSDate。还要考虑的问题可能是你的UIDATEPICKER的设置——你可能不知怎么地初始化了假脱机。@热舔一切似乎正确设置。我无法重新创建此问题,但我有时会收到来自用户的崩溃报告。这似乎是随机的,正如您所看到的,日期格式是正确的。我们不知道NSDateFormatter正确解析了日期。它本可以归零的(如你是一头野兽)!我从来没想过。当我和其中一个人谈论发生车祸的评论时,我意识到他说他来自爱尔兰。我把手机调到爱尔兰,复制了坠机事件。看来这就是罪魁祸首。将研究并返回。(“Feechure”是“编程艺术”的一个合法术语。)检查上面的链接。具体请参见。