2

Basically I have an app finished. My only problem ATM is that the app was designed with solely a 4-in display in mind. When run on a 3.5 in simulator theres .5 inches of the app missing (obviously).

My question, then, is how can I, in Xcode 5, set a different storyboard for a different screen size?

I know that before I could use the following piece of code:

-(void)initializeStoryBoardBasedOnScreenSize {

if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPhone)
{    // The iOS device = iPhone or iPod Touch


CGSize iOSDeviceScreenSize = [[UIScreen mainScreen] bounds].size;

if (iOSDeviceScreenSize.height == 480)
{   // iPhone 3GS, 4, and 4S and iPod Touch 3rd and 4th generation: 3.5 inch screen (diagonally measured)

    // Instantiate a new storyboard object using the storyboard file named Storyboard_iPhone35
    UIStoryboard *Main_iPhone2 = [UIStoryboard storyboardWithName:@"Main_iPhone3" bundle:nil];

    // Instantiate the initial view controller object from the storyboard
    UIViewController *initialViewController = [Main_iPhone2 instantiateInitialViewController];

    // Instantiate a UIWindow object and initialize it with the screen size of the iOS device
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

    // Set the initial view controller to be the root view controller of the window object
    self.window.rootViewController  = initialViewController;

    // Set the window object to be the key window and show it
    [self.window makeKeyAndVisible];
}

if (iOSDeviceScreenSize.height == 568)
{   // iPhone 5 and iPod Touch 5th generation: 4 inch screen (diagonally measured)

    // Instantiate a new storyboard object using the storyboard file named Storyboard_iPhone4
    UIStoryboard *Main_iPhone = [UIStoryboard storyboardWithName:@"Main_iPhone" bundle:nil];

    // Instantiate the initial view controller object from the storyboard
    UIViewController *initialViewController = [Main_iPhone instantiateInitialViewController];

    // Instantiate a UIWindow object and initialize it with the screen size of the iOS device
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

    // Set the initial view controller to be the root view controller of the window object
    self.window.rootViewController  = initialViewController;

    // Set the window object to be the key window and show it
    [self.window makeKeyAndVisible];
}

} else if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad)

{   // The iOS device = iPad

UISplitViewController *splitViewController = (UISplitViewController *)self.window.rootViewController;
UINavigationController *navigationController = [splitViewController.viewControllers lastObject];
splitViewController.delegate = (id)navigationController.topViewController;

}
}

But the deal with Xcode 5, and what I believe the reason this code isn't working is that there is a section in under general within your project that establishes a storyboard as the main one throughout the specific device type.

So, either there's a different way of doing the whole separate storyline thing, or I'm doing something wrong with the code. The following code obviously was placed under the AppDelegate.m file... so don't think I have anything wrong there.

Thanks, and really help would be greatly appreciated here. I really want to submit this app!!!

Regards, Patricio

Patricio Guerra
  • 2,277
  • 2
  • 13
  • 11

1 Answers1

0

In my - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions method in my App delegate, I have this block:

// Override point for customization after application launch.
if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone){
    UIStoryboard *storyBoard;

    CGSize result = [[UIScreen mainScreen] bounds].size;
    CGFloat scale = [UIScreen mainScreen].scale;
    result = CGSizeMake(result.width * scale, result.height * scale);

    if(result.height != 1136){
        storyBoard = [UIStoryboard storyboardWithName:@"MainStoryboard35" bundle:nil];
        UIViewController *initViewController = [storyBoard instantiateInitialViewController];
        [self.window setRootViewController:initViewController];
    }
}

Which overrides my default MainStoryboard, for the 4 inch screen, and loads my 3.5 inch screen storyboard. In my project, I still have the MainStoryboard (the 4 inch screen version) defined as the main interface.

This works in Xcode 5. And it's in a shipping app, so it should work just fine.

frankfle
  • 111
  • 4