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

家住魔仙堡 提交于 2019-12-13 17:16:55

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/10853038/how-do-i-add-buttons-to-a-toolbar-within-an-ipad-popover

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!