我是Objective-c的新手。我正在尝试隐藏导航栏我使用此代码并且它的工作完美但问题是当我无法显示navigationItem的右边的BarButtonItem时隐藏导航栏/ p>
-(void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:YES];
self.navigationController.navigationBarHidden = YES;
// self.navigationItem.rightBarButtonItem.enabled = NO;
}
我将此代码用于navigationItem
-(void)loadBackButton{
/*UIBarButtonSystemItemDone */
buttonItem = [[UIBarButtonItem alloc] initWithTitle:@"Done" style:UIBarButtonItemStyleDone target:self action:@selector(dismiss:)];
self.navigationItem.rightBarButtonItem = buttonItem;
}
- (void)dismiss:(id)sender {
NSLog(@"Dismis Done");
[self dismissModalViewControllerAnimated:YES];
//[self.view removeFromSuperview];
}
我的- (void)viewDidLoad
吼叫
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor whiteColor];
//for load navigationItem's
[self loadBackButton];
self.navigationItem.rightBarButtonItem.enabled = YES;
// Do any additional setup after loading the view from its nib.
}
答案 0 :(得分:2)
隐藏NavigationBar也会隐藏您的rightBarButtonItem
。其中一个可能的解决方案是使导航栏透明。您可以使用以下代码执行此操作:
[self.navigationController.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
self.navigationController.navigationBar.shadowImage = [UIImage new];
self.navigationController.navigationBar.translucent = YES;
self.navigationController.view.backgroundColor = [UIColor clearColor];