UINavigationBar不会在Apple TV上的第二个ViewController上显示

时间:2015-12-28 12:19:56

标签: uinavigationcontroller apple-tv

我在AppDelegate中有以下代码:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    UIStoryboard* sb = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
    UIViewController* viewController = [sb instantiateViewControllerWithIdentifier:@"ViewController"];

    UINavigationController* navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];

    UILabel* topBar = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 150, 30)];
    topBar.text = @"Custom Navigation";

    [navigationController.navigationBar.topItem setTitleView:topBar];

    self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
    [self.window setRootViewController:navigationController];
    [self.window makeKeyAndVisible];
    return YES;
}

My screen has a unbutton and appear like

单击该按钮时,将运行以下代码;

UIStoryboard* sb = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
UIViewController* second = [sb instantiateViewControllerWithIdentifier:@"second"];
[self.navigationController setNavigationBarHidden:NO];
[self.navigationController pushViewController:second animated:YES];

导航栏始终隐藏在第二个屏幕上。我尝试了[self.navigationController setNavigationBarHidden:NO][self.navigationController.navigationBar setHidden:NO],但它不起作用。

我的代码在iPhone或iPad上成功运行,但在Apple TV上无效。 在第二个屏幕上显示导航栏的解决方案是什么?

1 个答案:

答案 0 :(得分:0)

请勿在Apple TV上使用UINavigationBar。 UITabBar更有用。如果您创建自定义选项卡栏,请将UITabBarController实现到您的界面并将以下代码写入viewDidLoad方法。

getCount()