0

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

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 raise:format:arguments:] + 96 3 Foundation 0x398e62aa -[NSAssertionNumberHandler handleFailureInMethod:object:: :] + 86 4
UIKit 0x3736be20 -[_UIDatePickerView _setDate:animated:forced:] + 144 5 UIKit 0x373742d4 -[_UIDatePickerView setDate:animated:] + 28 6 UIKit
0x3743d464 -[UIDatePicker setDate:] + 32

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

4

1 回答 1

1

Do like this,

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;
于 2012-12-10T04:47:59.687 回答