0

I've got an app on the app store, and there's a crash some users are experiencing that I can't replicate - for me it works fine. The crash is caused by this line of code:

timePicker.date = editingEvent.time;

where timePicker is an UIDatePicker, editingEvent is a custom object, and time is an NSDate property. Here's the backtrace:

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

Any ideas - what am I overlooking/what could be going wrong? How might I proceed from here to find out where the bug could be?

Jordan Smith
  • 10,310
  • 7
  • 68
  • 114
  • 1
    difficult to tell without additional details, but i did a simple experiment where I set myDatePicker.date=nil and it crashed. So I would definitely look at cases where editingEvent can be nil – Srikanth Dec 10 '12 at 02:16
  • use the setter property to set the date – Bhupesh Dec 10 '12 at 04:25

1 Answers1

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;
Venk
  • 5,949
  • 9
  • 41
  • 52