Displaying a UIDatePicker inside of a UIPopover

前端 未结 2 611
你的背包
你的背包 2021-01-03 06:58

I\'m using the following code to display a UIDatePicker within a UIPopover that is displayed when a user clicks a UIButton.

Th

2条回答
  •  别那么骄傲
    2021-01-03 07:47

    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.

提交回复
热议问题