gpt4 book ai didi

ios - iOS9 中 UIDatePicker 崩溃

转载 作者:行者123 更新时间:2023-12-01 23:42:42 25 4
gpt4 key购买 nike

我在我的ViewController中使用了UIDatePicker。它在 iOS 8.x 上运行良好,但是当我在 iOS 9.x 设备上运行它时,它崩溃了。

我尝试创建一个新项目来以相同的方式使用 UIDatePicker,并且它在所有 iOS 设备上运行良好。

所以,我的问题是我的项目设置错误,还是我使用UIDatePicker的方式错误。

崩溃信息为:

click to see the crash log

我设置了一个断点,它只是在 iOS 9.3 上的 _datePicker.datePickerMode = UIDatePickerModeDate; 处崩溃,并且在 iOS 8.1 上运行良好。

- (UIDatePicker *)datePicker {
if (!_datePicker) {
NSDate *nowDate = [NSDate date];
_datePicker = [[UIDatePicker alloc] init];
_datePicker.datePickerMode = UIDatePickerModeDate;
_datePicker.hidden = YES;
_datePicker.backgroundColor = [UIColor whiteColor];
[_datePicker addTarget:self action:@selector(datePickerChanged) forControlEvents:UIControlEventValueChanged];
}
return _datePicker;
}

最佳答案

这是因为iOS 9更新引用了这个question这已经得到回答了。更新您的代码,如下所示。

  _datePicker = [[UIDatePicker alloc] init];
_datePicker.datePickerMode = UIDatePickerModeDateAndTime;
_datePicker.datePickerMode = UIDatePickerModeDate;

UIPickerView and UIDatePicker are now resizable and adaptive—previously, these views would enforce a default size even if you attempted to resize them. These views also now default to a width of 320 points on all devices, instead of to the device width on iPhone. Interfaces that rely on the old enforcement of the default size will likely look wrong when compiled for iOS 9. Any problems encountered can be resolved by fully constraining or sizing picker views to the desired size instead of relying on implicit behavior.

关于ios - iOS9 中 UIDatePicker 崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37807127/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com