这里我有两个观点:
- 欢迎VC
- WebViewVC
首先 AppDelegate 通过以下代码调用 WelcomeVC:
- (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;
}
所以在 WelcomeVC 中,导航栏不显示 navController.navigationBarHidden = YES;
。在WelcomeVC中,有一个调用WebViewVC的按钮,详情如下:
- (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:^{}];
}
按下此按钮时,我希望它调用 WebViewVC 并像我一样显示导航栏 [webViewController.navigationController setNavigationBarHidden:NO animated:NO];
但是什么我发现 WebViewVC 仍然没有导航栏。我还在 WebViewVC 中包含了 viewDidLoad,如下所示:
- (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];
}
有没有人可以帮助指导我哪里遗漏或做错了什么?那将不胜感激。提前致谢!
最佳答案
在这里,我通过更改 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];
}
关于ios - 导航栏不显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29899071/