我在“ 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/