Ios11将日历从格里高利变为日本或佛教的崩溃?

时间:2018-01-15 10:57:04

标签: iphone swift datepicker calendar ios11

var datePickerView: UIDatePicker = UIDatePicker() 
override func viewDidLoad() {
super.viewDidLoad()
initializeBarButtons() }
func initializeBarButtons() {  
datePickerView.datePickerMode = UIDatePickerMode.date // This is the line that gets the error
datePickerView.addTarget(self, action: #selector(EmployeeDetailEditViewController.handleDatePicker), for: UIControlEvents.valueChanged) 
  }

当日历从格里高利亚变为佛教徒时,此注释行导致崩溃。

崩溃: -

  

由于未捕获的异常终止应用' NSRangeException',原因:   ' * - [__ NSArrayM objectAtIndex:]:索引9223372036854775807以外   界限[0 .. 1]'   * 第一次抛出调用堆栈:(0x18626e364 0x1854b4528 0x186206e9c 0x186136840 0x18f9a1890 0x1902238a8 0x19022045c 0x1902210f4   0x19022139c 0x190214254 0x1902136cc 0x190213c08 0x190213d24   0x1013881e0 0x101386d1c 0x101387018 0x18f768590 0x18f768304   0x18f8d2bd4 0x18f7f5c4c 0x18f7f5890 0x18f7f5790 0x1a53e4c18   0x18f74cf00 0x18a2b1998 0x18a2b5b20 0x18a22236c 0x18a249b90   0x18a24a9d0 0x186215edc 0x186213894 0x186213e50 0x186133e58   0x187fe0f84 0x18f7b367c 0x10131b378 0x185c5056c)libc ++ abi.dylib:   以NSException类型的未捕获异常终止

如何解决这个问题?

1 个答案:

答案 0 :(得分:1)

很遗憾,您无法解决它,因为上面有一个敞开的雷达(https://openradar.appspot.com/41120005)。 同时,使用@Amey解决方法:

if #available(iOS 11.0, *) { 
    let gregorianCalendar = Calendar(identifier: .gregorian) 
    self.datePickerView.calendar = gregorianCalendar 
} else { 
    // Fallback on earlier versions 
}