I\'m using the following code to display a UIDatePicker
within a UIPopover
that is displayed when a user clicks a UIButton
.
Th
[popoverController presentPopoverFromRect:self.dateOfBirthButton.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
Use sender in place of self.view
[popoverController presentPopoverFromRect:((UIButton *)sender).bounds inView:sender permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
Is there a reason you couldn't just use a UIToolbar
?
UIToolbar* toolbar = [[UIToolbar alloc] initWithFrame: CGRectMake(0.0, 0.0, 320.0, 44.0)];
UIBarButtonItem* cancelButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem: UIBarButtonSystemItemCancel
target: self
action: @selector(cancel)];
UIBarButtonItem* space = [[UIBarButtonItem alloc] initWithBarButtonSystemItem: UIBarButtonSystemItemFlexibleSpace
target: nil
action: nil];
UIBarButtonItem* doneButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem: UIBarButtonSystemItemDone
target: self
action: @selector(done)];
NSMutableArray* toolbarItems = [NSMutableArray array];
[toolbarItems addObject:cancelButton];
[toolbarItems addObject:space];
[toolbarItems addObject:doneButton];
[cancelButton release];
[doneButton release];
[space release];
toolbar.items = toolbarItems;
Then just add the toolbar to your view. Make sure to size it correctly and implement the done
and cancel
selectors.