Instead of inputView approach, you can follow another approach to show datePicker on button click
Let showDatePicker
is the method called on button click then
-(void)showDatePicker
{
UIDatePicker* picker = [[UIDatePicker alloc] init];
picker.autoresizingMask = UIViewAutoresizingFlexibleWidth;
picker.datePickerMode = UIDatePickerModeDate;
[picker addTarget:self action:@selector(dueDateChanged:) forControlEvents:UIControlEventValueChanged];
CGSize pickerSize = [picker sizeThatFits:CGSizeZero];
picker.frame = CGRectMake(0.0, 250, pickerSize.width, 460);
picker.backgroundColor = [UIColor blackColor];
[self.view addSubview:picker];
}
-(void) dueDateChanged:(UIDatePicker *)sender {
NSDateFormatter* dateFormatter = [[[NSDateFormatter alloc] init] autorelease];
[dateFormatter setDateStyle:NSDateFormatterLongStyle];
[dateFormatter setTimeStyle:NSDateFormatterNoStyle];
//self.myLabel.text = [dateFormatter stringFromDate:[dueDatePickerView date]];
NSLog(@"Picked the date %@", [dateFormatter stringFromDate:[sender date]]);
}
To remove the datePicker, you can use removeFromSuperView
on either method called from another button click in your View or your custom toolbar
done button.