Search code examples
objective-cios7model-view-controlleruiviewcontrollerstoryboard

Navigation Controller. Navigation between multiple view controllers


![This is My view controller connection looks][1]

http://i58.tinypic.com/2mepfv4.png

![I have to go from view controller A to VC-B through programatically, Because it should satisfy login authentication based on device ID. Let me Explain Clearly. When user installs my app he should set up his email and verify.After verification He should move to VC-B.After moving VC-B, Viewcontroller-A should not open again when he opens app again. Something like kill View controller-A, and load VC-B whenever he opens app.

Question1- How to kill View controller-A completly.

Second thing i do not want to show navigation bar On View controller-A, But on View VC-B,VC-C and VC-D so on. i want to show navigation bar because user should be able to move back and forth.That's the reason i added navigation controller before VC-B again.

If i'm not able to show Navigation bar on VC-B until i enable show navigation bar on Navigation controller before View Controller A.

Question2-How to enable Navigation bar on VC-B but not on Viewcontroller-A.

][1] This is the code how am i moving from View controller A to VC-B.

    if (alertView.tag == 99) {
    if(buttonIndex == 0){
    VC-B *vcb =
    [self.storyboard instantiateViewControllerWithIdentifier:@"VC-B"];
      [self.navigationController pushViewController:vcb animated:YES];

} } Help me to point Right direction.


Solution

  • You do not necessarily need to kill the A view controller, I do not think this is a good idea.

    You can solve the issue by setting the info in NSUserDefaults when the user is successfully verified. Then navigate to the B view controller.

    In the method:

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    

    always check if that verified flag was set in NSUserDefaults, and if YES - set the rootViewController of the navigation controller to the B view controller, otherwise to the A view controller.

    To hide/unhide the Nav Bar, you can do it from any view controller (assuming they belong to a navigation controller), using this code:

    self.navigationController.navigationBar.hidden = YES; // or NO
    

    This code can be written in the view controller classes, inside viewDidLoad, viewWillAppear:, viewDidAppear:, or anywhere you need.

    There are also some methods if you want a nice animation for hiding/unhiding.