ios - 导航栏不显示

标签 ios objective-c uinavigationcontroller navigationbar

这里我有两个观点:

  • 欢迎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/

相关文章:

ios - native Controller 的 preferredStatusBarStyle

Objective-C 最佳实践

swift - 单击单元格后,它向我传递了 2 个 View ,我该如何修复它?

ios - 选项卡栏 Controller 中两个选项卡项的相同 View

javascript - document.addEventListener ("touchmove",阻止行为,假); - 阻止我使用溢出 : scroll; - work around?

ios - iOS:如果没有GPS,是否可以检测用户是否在驾驶车辆?

ios - Xcode:如何更改通知中心的应用程序名称

objective-c - Core Data 中的 'indexing' 到底是什么?

ios - 如何将两个 UIImage 添加到 UITableView 背景

iphone - 添加的 UINavigationController 按钮是否需要自动释放?这个代码可以吗?