gpt4 book ai didi

ios - UIToolbar 不显示 UIBarButtonItem

转载 作者:IT王子 更新时间:2023-10-29 08:02:18 26 4
gpt4 key购买 nike

我正在使用一个 Storyboard,并且我有一个 Split View,其中主视图是一个 UITableViewController。与 iPad 邮件应用程序一样,我想显示一个 UIToolbar。

我无法通过 Storyboard添加工具栏,但我设法以编程方式添加了它。我还可以将 UILabel 添加到工具栏,但我找不到添加刷新按钮或任何类型的 UIBarButtonItem 的方法。

有什么想法吗?

- (void)viewDidLoad {
[super viewDidLoad];

[self.navigationController setToolbarHidden:NO];

UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(50.0f, 0.0f, 80.0f, 40.0f)];
label.text = @"last updated...";
label.textAlignment = UITextAlignmentCenter;
label.font = [UIFont systemFontOfSize:13.0];
[self.navigationController.toolbar addSubview:label];

UIBarButtonItem *item1 = [[UIBarButtonItem alloc] initWithTitle:@"Item" style:UIBarButtonItemStylePlain target:self action:@selector(action:)];
UIBarButtonItem *item2 = [[UIBarButtonItem alloc] initWithTitle:@"Item1" style:UIBarButtonItemStyleBordered target:self action:@selector(action:)];

NSArray *buttons = @[item1, item2, nil];
[self.navigationController.toolbar setItems:buttons animated:NO];

最佳答案

感谢 Apple iOS 论坛找到了答案!

当您使用导航 Controller 的工具栏时,您必须在 active View Controller 的 toolbarItems 属性上设置工具栏按钮,而不是在实际导航 Controller 的工具栏本身上.

来自UINavigationController docs :

Displaying a Toolbar

A navigation controller object manages an optional toolbar in its view hierarchy. When displayed, this toolbar obtains its current set of items from the toolbarItems property of the active view controller. When the active view controller changes, the navigation controller updates the toolbar items to match the new view controller, animating the new items into position when appropriate.

例如:

[self setToolbarItems:buttons animated:NO];

关于ios - UIToolbar 不显示 UIBarButtonItem,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10825572/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com