Push / Pop View Controller With Navigation Bar from View Controller Without Navigation Bar

后端 未结 2 1637
广开言路
广开言路 2020-12-08 16:00

I\'m trying to push a view controller with a visible navigation bar from a view controller with a hidden navigation bar.

I tried all sorts of combinations of

2条回答
  •  Happy的楠姐
    2020-12-08 16:56

    I just set up two view controllers to test this back and forth.

    @interface VC1 ()
    
    @end
    
    @implementation VC1
    
    - (void)viewDidLoad {
    [super viewDidLoad];
    }
    
    - (void)viewWillAppear:(BOOL)animated
    {
    [super viewWillAppear:animated];
    self.navigationController.navigationBarHidden = YES;
    }
    
    @end
    

    and a second

    #import "ViewControllerTwo.h"
    
    @interface ViewControllerTwo ()
    
    @end
    
    @implementation ViewControllerTwo
    
    - (void)viewDidLoad {
        [super viewDidLoad];
    }
    
    - (void)viewWillAppear:(BOOL)animated
    {
        [super viewWillAppear:animated];
        self.navigationController.navigationBarHidden = NO;
    }
    
    @end
    

    VC1 is embedded in a navigationController (which is the root controller for the app), with a button that navigates to ViewControllerTwo. I have a push segue from VC1 -> ViewControllerTwo, this method works. When I tap on the button, the view controller is visible on ViewControllerTwo, when I press back, the navigationBar is gone.

提交回复
热议问题