我在应用程序商店中有一个应用程序,有些用户遇到了我无法复制的崩溃-对我来说,它运行正常。崩溃是由以下代码行引起的:

timePicker.date = editingEvent.time;


其中timePicker是UIDatePicker,editingEvent是自定义对象,而time是NSDate属性。这是回溯:


  最后异常回溯:0 CoreFoundation
    0x3785029e __exceptionPreprocess + 158 1 libobjc.A.dylib
    0x3535097a objc_exception_throw + 26 2 CoreFoundation
    0x37850158 + [NSException提高:格式:参数:] + 96 3基础
    0x398e62aa-[NSAssertionHandler
  handleFailureInMethod:object:file:lineNumber:description:] + 86 4
  UIKit 0x3736be20-[_ UIDatePickerView
  _setDate:animated:forced:] + 144 5 UIKit 0x373742d4-[_ UIDatePickerView setDate:animated:] + 28 6 UIKit
    0x3743d464-[UIDatePicker setDate:] + 32


任何想法-我忽略了什么/可能出了什么问题?我如何从这里继续找出错误所在?

最佳答案

这样吧

NSDate *date = [NSDate date];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"hh:mm a"];
NSString *formattedDateString = [dateFormatter stringFromDate:editingEvent.time];

NSDateFormatter *timeFormatter = [[NSDateFormatter alloc] init];
[timeFormatter setDateFormat:@"hh:mm a"];
NSDate *timeFromString = [[NSDate alloc] init];
timeFromString = [timeFormatter dateFromString:formattedDateString];
timePicker.date=timeFromString;

关于iphone - 设置UIDatePicker日期时崩溃,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/13793801/

10-14 18:27
查看更多