ipatch
ipatch

Reputation: 4043

How to develop for multiple iOS devices, i.e. multiple storyboards?

I am currently developing an app for the iPhone 3GS. The deployment target is set to 5.1 and I have created a rich storyboard with lots of segues and scenes. Last night I had the idea that I wanted to make the app available for the iPad, iPhone 4, and iPhone 5. I decided to create a separate storyboard for the different screen sizes / resolutions. Now I am not sure if this is the best practice, as I have just recently started reading about springs and struts on SO, so I don't know much information about it, but for my sake, I just wanted to launch a different storyboard when the application finished launching. However this desired effect is not happening.

AppDelegate.m

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // Override point for customization after application launch.
    // ViewControllerWelcome *viewControllerWelcome = (ViewControllerWelcome *)[[ViewControllerWelcome alloc]init];

//    NSManagedObjectContext *context = (NSManagedObjectContext *) [self managedObjectContext];
//    if (!context) {
//        NSLog(@"\nCould not create *context for self");
//    }

    //[viewControllerWelcome setManagedObjectContext:context];

    // Do I need to declare my view controllers here?

    // Pass the managed object context to the view controller.

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

    if (iOSDeviceScreenSize.height == 480)
    {
        // Instantiate a new storyboard object using the storyboard file named iPhoneLegacy
        UIStoryboard *iPhoneLegacy = [UIStoryboard storyboardWithName:@"iPhoneLegacy" bundle:nil];

        // Instantiate the initial view controller object from the storyboard
        UIViewController *ViewControllerWelcome = [iPhoneLegacy 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 = ViewControllerWelcome;

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

    if (iOSDeviceScreenSize.height == 968)
    {
        // Instantiate a new storyboard object using the storyboard file named iPhone4
        UIStoryboard *iPhone4 = [UIStoryboard storyboardWithName:@"iPhone4" bundle:nil];

        UIViewController *ViewControllerWelcome = [iPhone4 instantiateInitialViewController];
        self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
        self.window.rootViewController  = ViewControllerWelcome;
        [self.window makeKeyAndVisible];
    }

    // iPhone 5 1136 x 640

    // iPad Legacy 1024 x 768

    return YES;
}

When I try testing to see if the different storyboard file are loading in the Simulator, Simulator just loads the iPhoneLegacy storyboard.

Does this code only work for the physical devices, and do I need separate code for the Simulator?

Upvotes: 2

Views: 4129

Answers (1)

cory ginsberg
cory ginsberg

Reputation: 2897

Fist of all, DELETE YOUR EXTRA STORYBOARDS! You only need one for the iPhone and one for the iPad.

There is a simple way to make a single storyboard for all iPhone/iPod Touch sizes.

  1. Keep only ONE storyboard for the iPhone screen size (including iPhone 5).
  2. Make a @2x file for all of your images.
  3. To switch between 3.5 and 4 inch size, Apple provides a button in the bottom right that looks like a rectangle with arrows pointing in or out - that button will switch between the 3.5 and 4 inch screen sizes.

That's it! No code is actually needed to make a single storyboard for each iPhone/iPod Touch.


For the iPad, you are going to need to create a new storyboard that is made for the iPad and you are going to need to update your UI code to make sure it's compatible with both iPhone and iPad screen sizes. Again, make sure to make @2x image sizes for the iPad as well.

Upvotes: 4

Related Questions