gpt4 book ai didi

objective-c - 在导航 Controller 上添加按钮(来自代码)并使它们消失

转载 作者:搜寻专家 更新时间:2023-10-30 20:10:34 25 4
gpt4 key购买 nike


我在“ View Controller ”上方的代码中添加了一个按钮:

@implementation HBViewController
.....
.....
.....

- (void)viewDidLoad
{
[super viewDidLoad];
okButton = [[UIBarButtonItem alloc] initWithTitle:@"Ok" style:UIBarButtonItemStyleBordered target:self action:@selector(okayButtonPressed)];

[self.navigationItem setRightBarButtonItem:okButton animated:NO];

}

- (void) okayButtonPressed{
NSLog(@"you pressed ok");
}

...但是我怎样才能隐藏按钮呢?

最佳答案

            //to disable

self.navigationItem.rightBarButtonItem.enabled = NO;

//to hide - hide means setting nil will remove that button

self.navigationItem.rightBarButtonItem = nil;


//if u want to show again then create and assign new button again

okButton = [[UIBarButtonItem alloc] initWithTitle:@"Ok"

style:UIBarButtonItemStyleBordered

target:self action:@selector(okayButtonPressed)];

[self.navigationItem setRightBarButtonItem:okButton animated:NO];

关于objective-c - 在导航 Controller 上添加按钮(来自代码)并使它们消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10718686/

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