-->

UIToolbar in a popover

2020-08-04 04:11发布

问题:

Is it possible to show toolbar items in a UIViewController inside a popover? I'm doing this in the viewDidLoad method of my view controller:

UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:nil action:nil];
    [self setToolbarItems:[NSArray arrayWithObject:addButton]];
    [addButton release];

Then I'm wrapping this view controller in a UINavigationController (which has a toolbar property, and according to the docs, I'm supposed to use the setToolbarItems method of UIViewController to add items to the toolbar), then presenting it in a popover.

I do not see the toolbar. Are toolbars unsupported when using a popover?

Thanks

回答1:

Figured it out, apparently the toolbar is hidden by default so you have to do this:

[self.navigationController setToolbarHidden:NO animated:NO];

To make it appear.