UIDatePicker Date Method Selects Incorrect Date: iPhone Dev

I get very strange behavior in UIDatePicker. I have a view with a date picker declared in an .h file as IBOutlet UIDatePicker * datePicker; with non-atomic property and conservation. datePicker is correctly linked in IB file.

In the code, I set the minimum, maximum, start date and action to call UICOntrolEventValueChanged using the following code

If (!currentDate) {
    initialDate = [NSDate date];
} else {
    initialDate = currentdate;
}

[datePicker setMinimumDate:[NSDate date]];
[datePicker setMaximumDate:[[NSDate date] addTimeInterval:5 * 365.25 * 24 * 60 * 60]]; // to get upto 5 years 
[datePicker setDate:initialDate animated:YES];

[datePicker addTarget:self action:@selector(getDatePickerValue:) forControlEvents:UIControlEventValueChanged];

In getDatePickerValue, I get a new date using datePicker.date.

When the view is closed (using the button made), I get the current date value using datePicker.date.

, currentDate, " ". , , pickerView. . ,

, , 9 2010 .
  datePicker.date 10 2010 .
  11 2010 . , .

NSLogs , ​​.

( 3.0), .

, . , - .

+5
2

. , , , - , .


1. Picker -

NSLocale *locale = [NSLocale currentLocale];
[dateFormatter setLocale:locale];

self.datePicker.locale = locale; 
self.datePicker.calendar = [locale objectForKey:NSLocaleCalendar];

.
2. "" datePicker, datePicker self.datePicker. , , .

, "", . , .

, , .

+5
IBOUTLET UIDatePicker *datePicker;
IBOUTLET UILabel *label;
}
-(void)click:(id)sender;


- (void)viewDidLoad {

    [super viewDidLoad];
    NSDate *dateFromPicker = [[NSDate alloc]init];
    [date setDate:dat animated:YES];
}
-(void)click:(id)sender {

    NSDate *selectDate = [datePicker date];
    NSString *dateString = [NSString stringWithFormat:@"%@",selectDate];

    [label setText:dateString];
}

,

+3

All Articles