简体   繁体   中英

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. Now i want to add my storyboards to my 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. I don't have any tabBarController Property etc.

Any idea how i can add different story boards to one 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.

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:

- (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.

   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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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