Search code examples
iosobjective-ciphoneuinavigationitem

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


i am new in objective-c .I am trying to hide navigationbar i used this code and it's work perfectly but problem is this when i hide navigationbar after i am failed to show navigationItem's rightBarButtonItem

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

}

i am used this code for 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];
}

and my - (void)viewDidLoad are bellow

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

Solution

  • Hiding NavigationBar will hide your rightBarButtonItem too. One of the possible solutions is that you make the Navigation Bar transparent. You can use following code to do so:

    [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];