导航栏不显示

Navigation bar not showing

这里我有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:^{}];    
}

按下此按钮时,我希望它调用 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];
}

有没有人可以帮助指导我哪里遗漏或做错了什么?那将不胜感激。提前致谢!

通话

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

在 - viewWillAppear 方法中

我还建议您使用

更新框架
webView = [[UIWebView alloc] initWithFrame:[UIScreen mainScreen] bounds]];

试试这个:

- (void)viewWillAppear:(BOOL)animated {

    self.navigationController.navigationBarHidden = NO;

}

在这里,我通过更改 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];

}