The navigation bar is not displayed

Here I have 2 opinions:

  • WelcomeVC
  • WebViewVC

The first AppDelegate calls WelcomeVC with this code below:

- (void)presentWelcomeViewController 
    WelcomeViewController *welcomeViewController = [[WelcomeViewController alloc] initWithNibName:@"WelcomeViewController" bundle:nil];

    welcomeViewController.title = @"Welcome to My App";

    UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:welcomeViewController];
    navController.navigationBarHidden = YES;

    self.viewController = navController;
    self.window.rootViewController = self.viewController;
}

      

So in WelcomeVC the navigation bar is not displayed with navController.navigationBarHidden = YES;

. In WelcomeVC is a button for calling WebViewVC , as described below:

- (IBAction)termsPressed:(id)sender {
    WebViewController *webViewController = [[WebViewController alloc] initWithNibName:nil bundle:nil];
    NSLog(@"Terms of Use");
    webViewController.urlPassed = @"http://.../term.html";
    webViewController.title = NSLocalizedString(@"Terms of Use", nil);
    [webViewController.navigationController setNavigationBarHidden:NO animated:NO];
    [self.navigationController presentViewController:webViewController animated:YES completion:^{}];    
}

      

When this button is clicked I want it to call WebViewVC with navbar presented as I do [webViewController.navigationController setNavigationBarHidden:NO animated:NO];

, but I found that WebViewVC is presented without navbar still. I also include viewDidLoad in WebViewVC as shown below:

- (void)viewDidLoad {
    [super viewDidLoad];

    CGSize screenSize = [[UIScreen mainScreen] bounds].size;
    if(screenSize.height == 480)
    {
        webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
    }
    else if(screenSize.height == 568)
    {
        webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 568)];
    }

    [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:urlPassed]]];
    [self.view addSubview:webView];
}

      

Can anyone help me where I am missing or is there something wrong? That would be greatly appreciated. Thanks in advance!

+3


source to share


3 answers


I found a solution here by changing the code of the WelcomeVC button :



- (IBAction)termsPressed:(id)sender {
    WebViewController *webViewController = [[WebViewController alloc] initWithNibName:nil bundle:nil];
    NSLog(@"Terms of Use");
    webViewController.urlPassed = @"http://.../term.html";

    UINavigationController *webViewNavController =[[UINavigationController alloc] initWithRootViewController:webViewController];

    webViewNavController.navigationBarHidden = NO;

    webViewNavController.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
    [self presentViewController:webViewNavController animated:YES completion:nil];

}

      

+3


source


Try the following:



- (void)viewWillAppear:(BOOL)animated {

    self.navigationController.navigationBarHidden = NO;

}

      

+2


source


Call

[webViewController.navigationController setNavigationBarHidden:NO animated:NO];

      

In Method - viewWillAppear

Also I recommend that you refresh the frame with

webView = [[UIWebView alloc] initWithFrame:[UIScreen mainScreen] bounds]];

      

+1


source







All Articles