Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/102.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
Ios UIDatePicker NSInternalInconsistencyException:意外的日历单位数错误_Ios_Swift_Uikit_Crashlytics_Uidatepicker - Fatal编程技术网

Ios UIDatePicker NSInternalInconsistencyException:意外的日历单位数错误

Ios UIDatePicker NSInternalInconsistencyException:意外的日历单位数错误,ios,swift,uikit,crashlytics,uidatepicker,Ios,Swift,Uikit,Crashlytics,Uidatepicker,我从Crashlysis那里得到了这个事故报告,上面说UIDatePicker中有错误。这是iOS中的bug吗?因为似乎只有在AppDelegate中才是接触我的应用程序的入口点 Fatal Exception: NSInternalInconsistencyException unexpected number of calendar units: 4 for format: EEE ├'day': d┤ HH.mm (expecting at least 5 elements) 完整错误堆

我从Crashlysis那里得到了这个事故报告,上面说UIDatePicker中有错误。这是iOS中的bug吗?因为似乎只有在AppDelegate中才是接触我的应用程序的入口点

Fatal Exception: NSInternalInconsistencyException
unexpected number of calendar units: 4 for format: EEE ├'day': d┤ HH.mm (expecting at least 5 elements)
完整错误堆栈:

Fatal Exception: NSInternalInconsistencyException
0  CoreFoundation                 0x184bb5d04 __exceptionPreprocess
1  libobjc.A.dylib                0x183e04528 objc_exception_throw
2  CoreFoundation                 0x184bb5bd8 +[NSException raise:format:]
3  Foundation                     0x185545c24 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:]
4  UIKit                          0x18eab9b38 -[_UIDatePickerMode_DateAndTime elements]
5  UIKit                          0x18eab3898 -[_UIDatePickerMode displayedCalendarUnits]
6  UIKit                          0x18eab98f8 -[_UIDatePickerMode_DateAndTime displayedCalendarUnits]
7  UIKit                          0x18eaa8448 -[_UIDatePickerView _setMode:]
8  UIKit                          0x18eaa8694 -[_UIDatePickerView setDatePickerMode:]
9  UIKit                          0x18e55ac68 -[UIDatePicker initWithCoder:]
10 UIKit                          0x18e727160 UINibDecoderDecodeObjectForValue
11 UIKit                          0x18e726e98 -[UINibDecoder decodeObjectForKey:]
12 UIKit                          0x18e57c0cc -[UIRuntimeConnection initWithCoder:]
13 UIKit                          0x18e727160 UINibDecoderDecodeObjectForValue
14 UIKit                          0x18e7272d8 UINibDecoderDecodeObjectForValue
15 UIKit                          0x18e726e98 -[UINibDecoder decodeObjectForKey:]
16 UIKit                          0x18e57b40c -[UINib instantiateWithOwner:options:]
17 UIKit                          0x18e35b17c -[UIViewController _loadViewFromNibNamed:bundle:]
18 UIKit                          0x18e10aee4 -[UIViewController loadView]
19 UIKit                          0x18dfecba4 -[UIViewController loadViewIfRequired]
20 UIKit                          0x18dfecad4 -[UIViewController view]
21 UIKit                          0x18e171680 -[UINavigationController _startCustomTransition:]
22 UIKit                          0x18e0932c8 -[UINavigationController _startDeferredTransitionIfNeeded:]
23 UIKit                          0x18e092f0c -[UINavigationController __viewWillLayoutSubviews]
24 UIKit                          0x18e092e0c -[UILayoutContainerView layoutSubviews]
25 UIKit                          0x1a3a651b8 -[UILayoutContainerViewAccessibility layoutSubviews]
26 UIKit                          0x18dfea2f8 -[UIView(CALayerDelegate) layoutSublayersOfLayer:]
27 QuartzCore                     0x188ba3ec8 -[CALayer layoutSublayers]
28 QuartzCore                     0x188ba7fa8 CA::Layer::layout_if_needed(CA::Transaction*)
29 QuartzCore                     0x188b16a98 CA::Context::commit_transaction(CA::Transaction*)
30 QuartzCore                     0x188b3ceb4 CA::Transaction::commit()
31 QuartzCore                     0x188b3dcf4 CA::Transaction::observer_callback(__CFRunLoopObserver*, unsigned long, void*)
32 CoreFoundation                 0x184b5d848 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__
33 CoreFoundation                 0x184b5b200 __CFRunLoopDoObservers
34 CoreFoundation                 0x184b5b7bc __CFRunLoopRun
35 CoreFoundation                 0x184a7bfb8 CFRunLoopRunSpecific
36 GraphicsServices               0x186913f84 GSEventRunModal
37 UIKit                          0x18e0502e8 UIApplicationMain
38 AwesomeApp                     0x100da4924 main (AppDelegate.swift:18)
39 libdyld.dylib                  0x18459e56c start

不幸的是,这是iOS 11以来UIDatePicker的一个bug。当设备处于区域和日历的特定设置时会发生这种情况。我可以重现的场景之一是:

  • 区域:印度尼西亚
  • 日历:佛教徒
解决此问题的一种方法是将日历专门设置为您想要的格式

let datePicker=UIDatePicker()
datePicker.calendar=.gregorian
便于在所有使用
UIDatePicker
的情况下访问。您可以创建如下扩展:

扩展UIDatePicker{ 静态func makeDatePicker(模式:UIDatePicker.mode,maximumDate:Date?=nil)->UIDatePicker{ 让datePicker=UIDatePicker() datePicker.calendar=.gregorian datePicker.datePickerMode=模式 datePicker.maximumDate=maximumDate 返回日期选择器 } } 另外,不要忘记将此信息带到您的
日期格式化程序中。当
DateFormatter
启动时,它将使用设备默认日历。这可以通过以下方式实现:

let dateFormatter=dateFormatter()
dateFormatter.dateFormat=“dd/MM/yyyy”
dateFormatter.calendar=.gregorian
让dateString=dateFormatter.string(from:Date())

请显示您的
设置日期格式样式
code@QuocNguyen问题是,我不知道是哪部分代码导致了这种崩溃在我的例子中,这段代码导致了这种崩溃:让picker=UIDatePicker()picker.datePickerMode=.dateinterest finding。我来试试我们的解决方案。