I'm using the following code to display a UIDatePicker
within a UIPopover
that is displayed when a user clicks a UIButton
.
The problem is, it is being displayed in an awkward position and I want to add a UIToolBar
above the datePicker
where there is extra space. This will have cancel
and done
button. How can I accomplish this? The button that it is displayed from is the Date of Birth
one.
- (IBAction)dateOfBirthButtonPressed:(id)sender{
UIViewController* popoverContent = [[UIViewController alloc] init];
UIView *popoverView = [[UIView alloc] init];
popoverView.backgroundColor = [UIColor blackColor];
UIDatePicker *datePicker=[[UIDatePicker alloc]init];
datePicker.frame=CGRectMake(0,44,320, 216);
datePicker.datePickerMode = UIDatePickerModeDateAndTime;
[datePicker setMinuteInterval:5];
[datePicker setTag:10];
// [datePicker addTarget:self action:@selector(dateChanged) forControlEvents:UIControlEventValueChanged];
[popoverView addSubview:datePicker];
popoverContent.view = popoverView;
UIPopoverController *popoverController = [[UIPopoverController alloc] initWithContentViewController:popoverContent];
popoverController.delegate=self;
[popoverContent release];
[popoverController setPopoverContentSize:CGSizeMake(320, 264) animated:NO];
[popoverController presentPopoverFromRect:self.dateOfBirthButton.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}