I'm having slight difficult understanding why the following code is crashing an app of mine:
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"MMMM d, yyyy"];
NSDate *date = [dateFormatter dateFromString:cDate];
datePicker.date = date;
NSString *dateStr = [dateFormatter stringFromDate:date];
[dateLabel setText:dateStr];
[dateFormatter release];
If I comment the above out, app is fine. Also if I change the dateFormat to the following no crash happens:
[dateFormatter setDateFormat:@"yyyy-MM-dd"];
In my UIDatePicker delegate, I have repeated code that looks like the following (and works great):
-(IBAction)datePickerValueChanged:(id)sender
{
NSDate *date = [datePicker date];
NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease];
[dateFormatter setDateFormat:@"MMMM d, yyyy"];
NSString *dateStr = [dateFormatter stringFromDate:date];
[dateLabel setText:dateStr];
}
The error I get is the following:
*** Assertion failure in -[UIDatePickerView _updateBitsForDate:andReload:animateIfNeeded:], /SourceCache/UIKit/UIKit-747.38/UIDatePicker.m:892
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid parameter not satisfying: date'
Thanks for any suggestions