How do I hide/show the right button in the Navigation Bar

前端 未结 18 1937
后悔当初
后悔当初 2020-12-12 19:25

I need to hide the right button in the Navigation Bar, then unhide it after the user selects some options.

Unfortunately, the following doesn\'t work:



        
18条回答
  •  时光说笑
    2020-12-12 19:57

    Credit has to go to learner for this answer which the answer is from this question:

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

    This is the answer, which is far more simple.

    //hide and reveal bar buttons
    -(void) hideAndDisableLeftNavigationItem
    {
        [self.navigationItem.leftBarButtonItem setTintColor:[UIColor clearColor]];
        [self.navigationItem.leftBarButtonItem setEnabled:NO];
    }
    
    -(void) showAndEnableLeftNavigationItem
    {
        [self.navigationItem.leftBarButtonItem setTintColor:[UIColor blueColor]];
        [self.navigationItem.leftBarButtonItem setEnabled:YES];
    }
    

    Then you just reference the method where you require it like within an (IBAction) like so:

    [self hideAndDisableLeftNavigationItem];//[self showAndEnableLeftNavigationItem]; to show again
    

    I tried all other methods and none worked, even referencing my button as a @property (...) UIBarButtonItem.... and nothing worked until I found this.

提交回复
热议问题