Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Navigation bar not showing

Here I have 2 views:

  • WelcomeVC
  • WebViewVC

First AppDelegate calls WelcomeVC through 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, navigation bar is not shown with navController.navigationBarHidden = YES;. In WelcomeVC, there is a button to call WebViewVC as detailed 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 pressed, I want it to call WebViewVC with navigation bar presented as I do [webViewController.navigationController setNavigationBarHidden:NO animated:NO]; but what I found is WebViewVC is presented without navigation bar 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];
}

Does anyone please help guide me where I am missing or doing wrong? That would be greatly appreciated. Thanks in advance!

like image 406
SanitLee Avatar asked Apr 27 '15 14:04

SanitLee


3 Answers

Here I found a solution by changing code for the button in WelcomeVC:

- (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];

}
like image 134
SanitLee Avatar answered Sep 20 '22 12:09

SanitLee


Try this:

- (void)viewWillAppear:(BOOL)animated {

    self.navigationController.navigationBarHidden = NO;

}
like image 26
Jaideep Nagra Avatar answered Sep 18 '22 12:09

Jaideep Nagra


call

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

In - viewWillAppear method

Also I recommend you update frame with

webView = [[UIWebView alloc] initWithFrame:[UIScreen mainScreen] bounds]];
like image 23
oks_ios Avatar answered Sep 22 '22 12:09

oks_ios