0
votes

While using Typhoon I came across this issue, but first some background.

  • I'm using a storyboard.
  • The storyboard starts in a home screen, then flows to login, then to the main screen (UITabBarController). I use navigation controller as root controller.
  • If the user is already logged in I want to show the main screen without showing the home or login screens. This could be done in the home screen viewDidLoad (other suggestions welcome).

The few things i've tried are:

  1. Using a segue from the home to the tabController but the home screen can be seen and the transition is animated (don't want this).

  2. Instantiating the tab controller (as below) from the storyboard but the dependencies are not injected. I understand that this is because the Typhoon storyboard is not used.

    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil]; UIViewController *vc1 = [storyboard instantiateViewControllerWithIdentifier:@"MyAuth"];

  3. I also tried using factory with Typhoon for the storyboard.

    public dynamic func storyboard() -> AnyObject {
    
        return TyphoonDefinition.withClass(TyphoonStoryboard.self){
            (definition) in
    
            definition.useInitializer("storyboardWithName:factory:bundle:"){
                (initializer) in                
    
                initializer.injectParameterWith("Main")
                initializer.injectParameterWith(self)
                initializer.injectParameterWith( NSBundle.mainBundle() )
    
            }
            definition.scope = TyphoonScope.Singleton; //Let's make this a singleton
    
        }    
    }
    
    ///Injection for tabbar controller
    public dynamic func tabBarViewController() -> AnyObject {
    
        return TyphoonDefinition.withClass(TabBarViewController.self){
        (definition) in
    
        }
    
    }
    

On the viewDidLoad I push the tabBarViewController (using the injected assembly) to the navigation controller but it doesn't have the tabs as specified on the storyboard.

func viewDidLoad() {
    super.viewDidLoad()

    if(userLoggedIn){
        self.navigationController?.pushViewController(self.injectedAssembly.storyboard().tabBarController(), animated: false)
    }
}

Thanks,

1

1 Answers

1
votes

ad 1. You can disable animations on segues you created in a storyboard by selecting the segue in the storyboard editor, switching to the attributes inspector of the segue and disabling the "Animates" checkbox.

ad 2. If the UIViewController which contains the code you posted was instantiated within a Typhoon injected UIViewController (for instance if you have this code within the home viewcontroller, you use plist integration, and the home viewcontroller is set as the initial viewcontroller in your storyboard), then you can access self.storyboard in the UIViewController. This storyboard will be a TyphoonStoryboard, therefore it will work.

ad 3. Just because you give Typhoon instructions on how to create your MainStoryboards and TabBarViewControllers, it doesn't mean Typhoon knows it should combine one with the other. Try using one of the withFactory: methods provided by TyphoonDefinition to instantiate your UIViewController using the correct storyboard (sorry for Obj-C instead of Swift)

- (MYViewController *)myViewController {
    return [TyphoonDefinition
            withFactory:[self storyboard]
            selector:@selector(instantiateViewControllerWithIdentifier:)
            parameters:^(TyphoonMethod *factoryMethod) {
                [factoryMethod injectParameterWith:@"MYViewControllerIdentifier"];
            }
            configuration:^(TyphoonFactoryDefinition *definition) {
                definition.classOrProtocolForAutoInjection = [MYViewController class];
            }];
}