Objective c 我想隐藏我的导航栏,但我想显示 navigationItem rightBarButtonItem

Objective c i want to hide my navigationbar but i want to show navigationItem's rightBarButtonItem

我是 objective-c 的新手。我正在尝试隐藏导航栏我使用了这段代码并且它工作得很好但是问题是当我无法显示 navigationItem 的 rightBarButtonItem 后隐藏导航栏

-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:YES];
    self.navigationController.navigationBarHidden = YES;
   // self.navigationItem.rightBarButtonItem.enabled = NO;

}

我将此代码用于导航项

-(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.
}

隐藏 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];