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

UINavigationBar does not show on second ViewController on 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;
}

当按钮被点击时,下面的代码是运行;

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 上不起作用。 副屏显示导航栏的解决方法是什么?

不要在 Apple TV 上使用 UINavigationBar。 UITabBar 更有用。如果您制作自定义标签栏,请将 UITabBarController 实现到您的界面并将休闲代码写入 viewDidLoad 方法。

 customView = [[[NSBundle mainBundle] loadNibNamed:@"CustomTopBar" owner:self        options:nil] objectAtIndex:0];
[self.view addSubview: customView];