mpemburn
mpemburn

Reputation: 2884

How do I add buttons to a toolbar within an iPad popover?

Hoping someone here has conquered this one 'cuz it's driving me crazy. My app includes a popover that is used to enter and edit information. I learned today that it's possible to show a toolbar at the bottom of the popover and that's great -- except that I cannot for the life of me get any buttons to show on said toolbar. Here's where we start:

UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController: editorViewer];
//*** This makes the toolbar visible
[navigationController setToolbarHidden:NO animated:NO];
//*** Create a 'trash' button
UIBarButtonItem *trashButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemTrash target: nil action: @selector(deleteItem)]; 
//*** Create an array of buttons
NSArray *buttons = [NSArray arrayWithObjects: trashButton, nil];

I've tried each of the following to add the button, with no success:

navigationController.toolbar.items = buttons;

and

[navigationController setToolbarItems: buttons]

and

[navigationController.toolbar setItems: buttons animated: NO];

I get a pretty little toolbar, no buttons.

Any idea of what I'm doing wrong?

Upvotes: 1

Views: 1587

Answers (1)

Kevin Low
Kevin Low

Reputation: 2682

While you do set the toolbar hidden state on the navigation controller, the tool bar items are taken from the navigation controller's top view controller's toolbarItems property.

In your case

editorView.toolbarItems = buttons;

or

[editorView setToolbarItems:buttons];

while

[navigationController setToolbarHidden:NO animated:NO];

remains the same.

Upvotes: 2

Related Questions