ios - 代码中的 UITabBarController 不显示导航栏

标签 ios objective-c uitabbarcontroller

我们使用 Storyboard在 Obj C 代码中创建了一个 UITabBarController。它工作正常,但是导航栏不会显示在任何 View 上。尝试过在 TabBarController 中创建导航栏和其他一些东西。大多数示例不显示导航栏...任何具体的代码示例将不胜感激,谢谢!这是 VDL 代码:

- (void)viewDidLoad {
    [super viewDidLoad];

    UITabBarItem * startTab = [[UITabBarItem  alloc]initWithTitle:@"Home" image:[UIImage imageNamed:@"HomeTab.png"] tag:0]; 
     UITabBarItem * helpTab = [[UITabBarItem  alloc]initWithTitle:@"Help" image:[UIImage imageNamed:@"InfoDarkTab.png"] tag:1]; 

     UIStoryboard * phone = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle: nil];
     StartListTVC *startVC = [phone instantiateViewControllerWithIdentifier:@"StartList"];
     HelpWebVC * helpVC  = [phone instantiateViewControllerWithIdentifier:@"HelpWeb"];

     startVC.tabBarItem = startTab;
     helpVC.tabBarItem  = helpTab;

     NSArray *myViewControllers = [[NSArray alloc] initWithObjects:
         startVC,
         helpVC, nil];

    [self setViewControllers:myViewControllers];

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

    }

最佳答案

您应该将 View Controller 嵌入到 UINavigationController 中,而不是 UITabBarController。

- (void)viewDidLoad {
    [super viewDidLoad];

    UITabBarItem * startTab = [[UITabBarItem  alloc]initWithTitle:@"Home" image:[UIImage imageNamed:@"HomeTab.png"] tag:0]; 
     UITabBarItem * helpTab = [[UITabBarItem  alloc]initWithTitle:@"Help" image:[UIImage imageNamed:@"InfoDarkTab.png"] tag:1]; 

     UIStoryboard * phone = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle: nil];
     StartListTVC *startVC = [phone instantiateViewControllerWithIdentifier:@"StartList"];
     HelpWebVC * helpVC  = [phone instantiateViewControllerWithIdentifier:@"HelpWeb"];


     UINavigationController *startNavVC = [[UINavigationController alloc] initWithRootViewController: startVC];
UINavigationController *helpNavVC = [[UINavigationController alloc] initWithRootViewController: helpVC];
     startNavVC.tabBarItem = startTab;
     helpNavVC.tabBarItem  = helpTab;
     NSArray *myViewControllers = [[NSArray alloc] initWithObjects:
         startNavVC,
         helpNavVC];

    [self setViewControllers:myViewControllers];
    }

关于ios - 代码中的 UITabBarController 不显示导航栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58259947/

相关文章:

ios - xcode 签名无效包含不允许的权利 ios 中的错误

javascript - 是否可以阻止 Cordova 的相机插件在设备上存储图像?

objective-c - 当返回值是不可变对象(immutable对象)时返回可变对象是不好的做法吗?

ios - 无法从 UITabViewController 中的 VC 中呈现 View Controller

ios - presentViewController 不显示标签栏或导航栏

ios - OpenCv iOS 相机预览单方向不拉伸(stretch)

ios - 如何从 Swift 中的 TableCell 类访问 UIViewController 类中的值?

iphone - 使用SocializeActionBar添加多个实体

objective-c - 开源钢琴键盘 ios

iphone - 可以向下滑动UITabBarController吗?