简体   繁体   English

将新的StoryBoard添加到UITabbarController

[英]Adding new StoryBoard to UITabbarController

I have many storyboards in my app. 我的应用程序中有很多故事板。 Earlier my app was not a UITabBar based app but now i decided to go in a more UITabBar way. 以前我的应用程序不是基于UITabBar的应用程序,但是现在我决定采用一种更UITabBar方式。 Now i want to add my storyboards to my UITabBarController . 现在,我要将情节UITabBarController添加到UITabBarController I opened one storyboard and embed that in the UITabBarController, but now i don't know how i can add other storybord's first UIViewControllers to my Tabbar. 我打开了一个情节提要板并将其嵌入到UITabBarController中,但是现在我不知道如何将其他Storybord的第一个UIViewControllers添加到我的Tabbar中。 I don't have any tabBarController Property etc. 我没有任何tabBarController属性等。

Any idea how i can add different story boards to one UITabBarController 任何想法我如何可以将不同的故事板添加到一个UITabBarController

如果您不想在一个情节提要板上全部移动,则应参考选项卡栏控制器,并以编程方式添加每个情节提要的初始视图控制器。

I guess my first question/concern would be why you have so many storyboards. 我想我的第一个问题/关注点是为什么您会有这么多故事板。 Why not have all your view controllers on a single storyboard? 为什么不将所有视图控制器都放在一个情节提要板上? If you had all your View Controllers on the same storyboard, then connecting them to UITabBarController is a trivial thing - control+drag a connection from the UITabBarController as many view controllers as you need. 如果您将所有View Controller放在同一个情节提要板上,那么将它们连接到UITabBarController就是一件很简单的事情-按住Control并从UITabBarController拖动一个所需的视图控制器即可。

If for some reason there is some requirement that you have view controllers distributed in multiple storyboards, then you should be able to load them programmatically in the following manner. 如果出于某种原因需要将视图控制器分布在多个情节提要中,则应该能够以以下方式以编程方式加载它们。 In a subclass of UITabBarController: 在UITabBarController的子类中:

- (void)viewDidLoad {
    [super viewDidLoad];
    UIStoryboard *storyboard1 = [UIStoryboard storyboardWithName:@"YourStoryBoardHNameHere1" bundle:nil];
    UIViewController *vc1 = [storyboard1 instantiateViewControllerWithIdentifier:@"YourVCNameHere1"];
    UIStoryboard *storyboard2 = [UIStoryboard storyboardWithName:@"YourStoryBoardHNameHere2" bundle:nil];
    UIViewController *vc2 = [storyboard2 instantiateViewControllerWithIdentifier:@"YourVCNameHere2"];
    self.viewControllers = @[vc1,vc2];
}

Swift 3 for N8P's answer: implementing TabBarController using multiple storyboards. N8P的答案是Swift 3:使用多个情节提要板实现TabBarController。

   func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
    // Override point for customization after application launch.

    let tabBar = UITabBarController()
    tabBar.viewControllers = self.getArrayOfViewControllers()
    self.customiseTabItems(tabBar: tabBar.tabBar)
    // set tabBar as root

    self.window?.rootViewController = tabBar
    self.window?.makeKeyAndVisible()
    return true
}

see example 看例子

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM