-(IBAction)showDate:(id)sender
{
datePicker = [[UIDatePicker alloc] initWithFrame:CGRectMake(0, 220, 325, 300)];
datePicker.datePickerMode = UIDatePickerModeDate;
datePicker.hidden = NO;
datePicker.date = [NSDate date];
[datePicker setDate:datePicker.date animated:YES];
[self.view addSubview:datePicker];
}
- (void)setDate:(NSDate *)date animated:(BOOL)animated
{
NSDateFormatter *df = [[NSDateFormatter alloc] init];
[df setDateFormat:@"dd/MM/yyyy"];
NSString *str = [df stringFromDate:date];
NSLog(@"String is------:%@",str);
[dateBtn setTitle:str forState:UIControlStateNormal];
}
i have gone through UIDatePicker Class reference in Apple’s Doc.Based on that i have implemented the code as above.there i am getting only current date on button when external method code is written in button action and not changing date if i am change in DatePicker.
if i write code like mention above, i dint get even any title on button.
i think, am made blunder mistake, can anyone tell me where the mistake is and explain me in detail.
Thanks alot for help in advance.
I think you are getting confused with subclassing, which is something you are not doing here (and don’t need to). You need to setup the date picker to call a method of your choosing when the date is changed; something like this:
(See reference).
And then implement the method: