I have a mysterious crash when I try to run the application on the iPhone (though it works fine on Simulator). I think the problem is in these 2 methods ..:
-(void)viewWillAppear:(BOOL)animated{ [self getValueFromPicker]; } -(void)getValueFromPicker{ NSDate *now = [NSDate date]; NSDate *birthDate = self.birthdayPicker.date; NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar]; NSDateComponents *components = [calendar components:NSYearCalendarUnit|NSMonthCalendarUnit|NSDayCalendarUnit fromDate:now toDate:birthDate options:0]; NSLog(@"Difference in years %i/", components.year); }
Application error with SIGABRT error, and there is text that I can see in the console: Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid parameter not satisfying: date'
Please help me, I really do not know what I did wrong, when I did the same on the Simulator in the console, I see the difference in years from the date and date of Now, the user selected.
Update: after removal [self defaultBirthdayPickerDate]; in the viewDidLoad section, it starts to work. But now the current date is displayed in the picker, which is not very convenient for choosing a date of birth, now I still need to change the current date from now to the past.
source share