gpt4 book ai didi

ios - 如何隐藏/显示导航栏中的右键

转载 作者:IT老高 更新时间:2023-10-28 11:45:53 24 4
gpt4 key购买 nike

我需要隐藏导航栏中的右键,然后在用户选择一些选项后取消隐藏。

很遗憾,以下方法不起作用:

NO GOOD: self.navigationItem.rightBarButtonItem.hidden = YES;  // FOO CODE

有办法吗?

最佳答案

通过将引用设置为 nil 来隐藏按钮,但是如果您想稍后恢复它,您需要保留它的副本以便重新分配它。

UIBarButtonItem *oldButton = self.navigationItem.rightBarButtonItem;
[oldButton retain];
self.navigationItem.rightBarButtonItem = nil;

//... later
self.navigationItem.rightBarButtonItem = oldButton;
[oldButton release];

就个人而言,在我的应用程序中,我将导航按钮设置为 @properties,以便我可以随意丢弃和重新创建它们,例如:

//mycontroller.h
UIBarButtonItem *rightNavButton;
@property (nonatomic, retain) UIBarButtonItem *rightNavButton;

//mycontroller.m
@synthesize rightNavButton;
- (UIBarButtonItem *)rightNavButton {
if (!rightNavButton) {
rightNavButton = [[UIBarButtonItem alloc] init];
//configure the button here
}
return rightNavButton;
}

//later, in your code to show/hide the button:
self.navigationItem.rightBarButtonItem = self.rightNavButton;

关于ios - 如何隐藏/显示导航栏中的右键,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5588767/

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