这里我有2个观点:
首先 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:^{}];
}
按下此按钮后,我希望它按照我[webViewController.navigationController setNavigationBarHidden:NO animated:NO];
显示的导航栏来调用 WebViewVC ,但我找到的是 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];
}
有人请帮助指导我错过或做错的地方吗?非常感谢。提前谢谢!
答案 0 :(得分:4)
在这里,我通过更改 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];
}
答案 1 :(得分:2)
试试这个:
- (void)viewWillAppear:(BOOL)animated {
self.navigationController.navigationBarHidden = NO;
}
答案 2 :(得分:1)
呼叫
[webViewController.navigationController setNavigationBarHidden:NO animated:NO];
In-viewWillAppear方法
另外,我建议您使用
更新框架webView = [[UIWebView alloc] initWithFrame:[UIScreen mainScreen] bounds]];