hide and show left navigation bar button on demand in iOS-7

前端 未结 3 2128
不思量自难忘°
不思量自难忘° 2021-02-15 17:33

I added my left navigation bar button using the storyboard. but I want it to hide when I first load the screen. And then in response to something else, I want it to show. The na

相关标签:
3条回答
  • 2021-02-15 17:53

    Here is how I solved it

    -(void) hideAndDisableRightNavigationItem
    {
        [self.navigationItem.rightBarButtonItem setTintColor:[UIColor clearColor]];
        [self.navigationItem.rightBarButtonItem setEnabled:NO];
    }
    
    -(void) showAndEnableRightNavigationItem
    {
        [self.navigationItem.rightBarButtonItem setTintColor:[UIColor blackColor]];
        [self.navigationItem.rightBarButtonItem setEnabled:YES];
    }
    
    0 讨论(0)
  • 2021-02-15 17:53

    Here is what I did. On the initial screen I wanted to hide the navigation bar:

     self.navigationController.navigationBarHidden = YES;
    

    On the second screen I wanted to show the navigation bar so I set:

     self.navigationController.navigationBarHidden = NO;
    
    0 讨论(0)
  • 2021-02-15 18:03

    Swift version of @learner answer

    func hideAndDisableRightNavigationItem (){
      self.navigationItem.rightBarButtonItem?.enabled = false
      self.navigationItem.rightBarButtonItem?.tintColor = UIColor.clearColor()
    }
    
    func showAndEnableRightNavigationItem(){
       self.navigationItem.rightBarButtonItem?.enabled = true
       self.navigationItem.rightBarButtonItem?.tintColor = UIColor. blackColor()
    }
    
    0 讨论(0)
提交回复
热议问题