如何在iPad弹出框内向工具栏添加按钮? [英] 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;
和
[navigationController setToolbarItems: buttons]
和
[navigationController.toolbar setItems: buttons animated: NO];
我有一个很小的工具栏,没有按钮.
I get a pretty little toolbar, no buttons.
有什么想法我做错了吗?
Any idea of what I'm doing wrong?
推荐答案
虽然您确实在导航控制器上设置了工具栏的隐藏状态,但工具栏项却取自导航控制器的顶视图控制器的工具栏项目属性.
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.
以您的情况
editorView.toolbarItems = buttons;
或
[editorView setToolbarItems:buttons];
同时
[navigationController setToolbarHidden:NO animated:NO];
保持不变.
这篇关于如何在iPad弹出框内向工具栏添加按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!