导航栏未显示 [英] Navigation bar not showing

查看:91
本文介绍了导航栏未显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这里有2个视图:

  • WelcomeVC
  • WebViewVC

首先 AppDelegate 通过以下代码调用 WelcomeVC :

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;
}

因此,在 WelcomeVC 中,导航栏未显示为navController.navigationBarHidden = YES;.在 WelcomeVC 中,有一个按钮可以调用 WebViewVC ,如下所述:

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:^{}];    
}

按下此按钮时,我希望它调用 WebViewVC ,并在显示导航栏的同时显示[webViewController.navigationController setNavigationBarHidden:NO animated:NO];,但是我发现的是 WebViewVC ,但没有导航栏仍然.我还在 WebViewVC 中包含了viewDidLoad,如下所示:

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!

推荐答案

在这里,我找到了一种解决方案,方法是更改​​ WelcomeVC 中按钮的代码:

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

}

这篇关于导航栏未显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆