IOS changes default display manager for storyboard at runtime

Is it possible to override the default view controller from the storyboard to display another controller instead? Of course, all this will happen in AppDelegate.

+5
source share
2 answers

@ Martol1ni I wanted to use your answer, but I also wanted to stay away from the unnecessary mess of the storyboard, so I changed your code a bit. However, I gave you +1 for your inspiring answer.

In the default controller, I placed all of the following.

- (void)gotoScreen:(NSString *)theScreen
{
    AppDelegate *app = (AppDelegate *)[[UIApplication sharedApplication] delegate];

    UIViewController *screen = [self.storyboard instantiateViewControllerWithIdentifier:theScreen];
    [app.window setRootViewController:screen];
}

And then, when logic happens, I will invoke the following if necessary.

if(myBool == YES) {
    [self gotoScreen:@"theIdentifier"];
}
+10
source

rootView UINavigationController, , . , . :

- (void) decideViewController  {
    NSString * result;
    if (myBool) {
        result = @"yourIdentifier";
    }
    else {
        result = @"yourOtherIdentifier";
    }
    self.navigationController.navigationBarHidden = YES; // Assuming you don't want a navigationbar
    UIViewController *screen = [self.storyboard instantiateViewControllerWithIdentifier:@"view1ident"];
    [self.navigationController pushViewController:screen animated:NO]; // so it looks like it the first view to get loaded
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    [self decideViewController];
}

, . NIBS, , AppDelegate, ...

+5

All Articles