我在应用程序商店有一个应用程序,有一些用户正在经历的崩溃,我无法复制 - 对我来说它工作正常。崩溃是由这行代码引起的:
timePicker.date = editingEvent.time;
其中timePicker是UIDatePicker,editingEvent是自定义对象,time是NSDate属性。这是回溯:
Last Exception Backtrace:0 CoreFoundation
0x3785029e __exceptionPreprocess + 158 1 libobjc.A.dylib
0x3535097a objc_exception_throw + 26 2 CoreFoundation
0x37850158 + [NSException raise:format:arguments:] + 96 3 Foundation 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
任何想法 - 我忽略了什么/可能出现什么问题?我如何从这里开始找出错误的位置?
答案 0 :(得分:1)
这样做,
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;