【问题标题】:How do I add buttons to a toolbar within an iPad popover?如何将按钮添加到 iPad 弹出框内的工具栏?
【发布时间】:2012-06-01 15:21:04
【问题描述】:

希望这里有人征服了这个,因为它让我发疯。我的应用程序包含一个用于输入和编辑信息的弹出框。我今天了解到,可以在弹出框的底部显示一个工具栏,这很棒——除了我一辈子都无法在所述工具栏上显示任何按钮。我们从这里开始:

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];

我尝试了以下每种方法来添加按钮,但均未成功:

navigationController.toolbar.items = buttons;

[navigationController setToolbarItems: buttons]

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

我有一个漂亮的小工具栏,没有按钮。

知道我做错了什么吗?

【问题讨论】:

    标签: ios sdk uibarbuttonitem uitoolbar popover


    【解决方案1】:

    当您在导航控制器上设置工具栏隐藏状态时,工具栏项目取自导航控制器的顶视图控制器的 toolbarItems 属性。

    你的情况

    editorView.toolbarItems = buttons;
    

    [editorView setToolbarItems:buttons];
    

    同时

    [navigationController setToolbarHidden:NO animated:NO];
    

    保持不变。

    【讨论】:

    • 祝福你!你让我很快乐!在考虑我使用工具栏的其他地方时,这是有道理的,尽管它表面上是违反直觉的。标记
    猜你喜欢
    • 2023-03-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-12-11
    相关资源
    最近更新 更多