0

I'm using the code bellow to check if the user is logged in or logged out, and it's working fine. But because I'm getting the storyboard by name, I'm always sending the user to the iPhone "in" or "out" view controller. It's gonna work if I get the active storyboard. How can I fix the code?

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    BOOL user = ...;
    NSString *segue = user ? @"in" : @"out";
    UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:@"iPhone" bundle:nil];
    UIViewController *viewController = [storyBoard instantiateViewControllerWithIdentifier:segue];
    [self.window setRootViewController:viewController];

    return YES;
}
lolol
  • 4,287
  • 3
  • 35
  • 54

1 Answers1

1

If all you're looking to do is to get the viewController from a different storyboard depending on whether your app is running on an iPad vs. an iPhone, you could do this with an if statement:

NSString *storyboardName;
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
    storyboardName = @"iPad";
} else {
    storyboardName = @"iPhone";
}
UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:storyboardName bundle:nil];

If you really need to get the "active" storyboard no matter the situation, this prior answer may help you:

UIStoryboard: What's the Correct Way to Get the Active Storyboard?

Community
  • 1
  • 1
jonkroll
  • 15,682
  • 4
  • 50
  • 43