我在“视图控制器”上面的代码中添加了一个按钮:
@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");
}
......但我该如何隐藏按钮?
答案 0 :(得分:2)
//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];
答案 1 :(得分:1)
self.navigationItem.rightBarButtonItem = nil;
答案 2 :(得分:0)
只需将其设为零
[self.navigationItem setLeftBarButtonItem:nil animated:YES];