Here I have 2 views:
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!
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];
}
Try this:
- (void)viewWillAppear:(BOOL)animated {
self.navigationController.navigationBarHidden = NO;
}
call
[webViewController.navigationController setNavigationBarHidden:NO animated:NO];
In - viewWillAppear method
Also I recommend you update frame with
webView = [[UIWebView alloc] initWithFrame:[UIScreen mainScreen] bounds]];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With