I have been trying to fix this issue since so long but did not find any way to sort this out.
When I'm trying to select a year sometimes the year component of the date picker jumps to a random year. (The same thing happens with date and month selection)
The data picker is contained in a UIView and I have created an IBOutlet for it.
- (void)setupforBirthdates {
[self.dtPicker setDatePickerMode: UIDatePickerModeDate];
NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier: NSCalendarIdentifierGregorian];
NSDate *currentDate = [NSDate date];
NSDateComponents * comps = [[NSDateComponents alloc] init];
[comps setYear: -17];
NSDate * maxDate = [gregorian dateByAddingComponents: comps toDate: currentDate options: NSCalendarMatchStrictly];
[comps setYear: -50];
NSDate * minDate = [gregorian dateByAddingComponents: comps toDate: currentDate options: NSCalendarMatchStrictly];
[self.dtPicker setMinimumDate:minDate];
[self.dtPicker setMaximumDate:maxDate];
[self.dtPicker setDate:maxDate];
}
ISSUE See the below image...
I thought that it may be due to some 3rd party libraries this is happening. I have the following pod in my project
pod 'AFNetworking'
pod 'GoogleMaps'
pod 'GooglePlaces'
pod 'Fabric'
pod 'Crashlytics'
pod 'RACollectionViewReorderableTripletLayout'
pod 'FBSDKLoginKit'
pod 'Socket.IO-Client-Swift', '~> 13.3.0'
How can I solve this issue?
Any help/suggestions?
UPDATE
I what to restrict user to select birth year from 17 to 50 year only so the minDate will be 17 years back from current year maxDate will be 50 years back from the current year
The issue is also coming if I don't set minDate and maxDate
Tested the following case too
I just drag and drop new date picker on screen. I did not set any min/max date, nor connect an IBOutlet and I run app and when I scroll to any date the same issue is coming
You will be surprised that I have created a custom date picker using
UIPickerViewand the issue is still there.When I have created a new demo project and copy pasted the code in demo project then this issue is not coming. I've tested it many times on demo project the issue is not coming.
The following func. is called when I change the date in date picker.
- (IBAction)datePickerValueChanged:(id)sender {
NSDateFormatter *dateFormat=[[NSDateFormatter alloc]init];
[dateFormat setDateFormat:@"yyyy-MM-dd"];
self.txtBirthday.text = [NSString stringWithFormat:@"%@",[dateFormat stringFromDate:self.dtPicker.date]];
}
from UIDatePicker: While selecting date, it jumps to any random date

No comments:
Post a Comment