gpt4 book ai didi

iphone - UINavigationController工具栏: problem setting UIBarButtonItems

转载 作者:行者123 更新时间:2023-12-03 20:48:11 24 4
gpt4 key购买 nike

 -(void)viewWillAppear:(BOOL)animated {
//setup toolbar
[self.navigationController setToolbarHidden:NO];
self.navigationController.toolbar.barStyle = UIBarStyleBlackTranslucent;
self.navigationController.toolbar.alpha = .8;
self.navigationController.toolbar.tintColor = [UIColor colorWithRed:6.0/255.0 green:95.0/255.0 blue:163.0/255.0 alpha:1];

//setup items
UIBarButtonItem *item1 = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self.navigationController.toolbar action:nil];
UIImage *imageUp = [UIImage imageNamed:@"up.png"];
UIBarButtonItem *item2 = [[UIBarButtonItem alloc] initWithImage:imageUp style:UIBarButtonItemStylePlain target:self action:@selector(toggleUp:)];
item2.width = 5;
UIImage *imageDown = [UIImage imageNamed:@"down.png"];
UIBarButtonItem *item3 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:self action:nil];
UIBarButtonItem *item4 = [[UIBarButtonItem alloc] initWithImage:imageDown style:UIBarButtonItemStylePlain target:self action:@selector(toggleDown:)];
UIBarButtonItem *item5 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:self action:nil];
UIBarButtonItem *item6 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh target:self action:@selector(toggleDown:)];
UIBarButtonItem *item7 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil];


NSArray *itemsArray = [[NSArray alloc] initWithObjects:item1, item2, item3, item4, item5, item6, item7, nil ];


[self setToolbarItems:itemsArray];


...more

}

我不确定这里发生了什么,我已经阅读了很多有关如何处理工具栏的内容,但我似乎无法显示任何 UIBarButtonItems。

有什么想法吗?

最佳答案

很抱歉上面的代码困惑。

我已经找到了问题的答案。我正在访问 UINavigationController 的子级,而不是根 UIView。我将上面的代码分配给 viewWillAppear 到我的 UINavigationController 的根 UIViewController 并且它起作用了。因此,为了仅在我的子 UIViewController 上显示它,我必须设置

[self.navigationController setToolbarHidden:NO];

对于我不希望工具栏可见的所有 UIViewController。

希望这可以帮助别人。谢谢

关于iphone - UINavigationController工具栏: problem setting UIBarButtonItems,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3661508/

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