Pergunta

I have tabbed application and 3 tabs contain exactly the same screens just with different data .

To implement functionality of those screens i used split view controller. What i need to do is create 3 tabs that all use this split view controller(with the same master and detail view controllers) without duplicating master and detail view controllers three times in storyboard.

I tried creating three split view controllers and linking all of them to one master view controller and one detail view controller but that didn't work. Only one of those controllers actually used them. Other just showed black screen.

Any tips on how can this be done?

Foi útil?

Solução

I think I got it to work using the following:

In storyboard, Split View Controller's Storyboard ID is 'splitVc':

Storyboard Layout

Then, I used the following code in my AppDelegate:

- (BOOL)application:(UIApplication *)application 
    didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    UISplitViewController *splitVc1 = [self.window.rootViewController.storyboard
        instantiateViewControllerWithIdentifier:@"splitVc"];

    UISplitViewController *splitVc2 = [self.window.rootViewController.storyboard
        instantiateViewControllerWithIdentifier:@"splitVc"];

    UISplitViewController *splitVc3 = [self.window.rootViewController.storyboard
        instantiateViewControllerWithIdentifier:@"splitVc"];

    UITabBarController *tabBarVc    = (UITabBarController *)self.window.rootViewController;

    tabBarVc.viewControllers        = @[splitVc1, splitVc2, splitVc3];
    return YES;
}

This gave me what appeared to be 3 separate instances of the UISplitViewController, each assigned to 1 of 3 tabs in the UITabBarController, which is the root view controller for my UIWindow.

Is that what you wanted?

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top