Alosyius
Alosyius

Reputation: 9121

iOS iPad storyboard is not being selected

It seems that Xcode 5 is not choosing to use my iPad storyboard for the iPad device even though i specified it.

This is how i told Xcode 5 to use iPad storyboard:

But for some reason even though i make changes to my MainStoryboard-iPad storyboard its not being showed when i try to run it on an iPad.

I only have two storyboards in my project

MainStoryboard-iPad.storyboard

and

MainStoryboard.storyboard

Any ideas what could be wrong here?

Oh by the way, when i selected Universal the first time i got a box asking me something about copying (i never read it that carefully). I just hit Yes. Not sure what that box actually did.

EDIT

Code that runs in my AppDelegate.m

- (void)applicationDidBecomeActive:(UIApplication *)application {
        AppDelegate *app = [[UIApplication sharedApplication] delegate];
        UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
        UIViewController *ivc = [storyboard instantiateViewControllerWithIdentifier:@"mainStoryBoard"];

        UINavigationController *nvc = (UINavigationController*)self.window.rootViewController;
        app.window.rootViewController = ivc;
}

Upvotes: 3

Views: 3536

Answers (5)

Basil Mariano
Basil Mariano

Reputation: 2675

I just encountered this a while ago.

These are the steps you need to do:

  1. make sure the "Deployment Info" -> Devices is "Universal"
  2. Create a storyboard for iPad (e.g) MainStoryboard_iPad.storyboard
  3. now go to your Infor.plist
  4. add row for "Main storyboard file base name (iPad)" and use MainStoryboard_iPad as the value of the string

Now you are good to go!

Upvotes: 3

Raja Harris
Raja Harris

Reputation: 11

// Override point for customization after application launch.

if (<your implementation>) {

    UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"Main" 
                                                             bundle: nil];
    YourViewController *yourController = (YourViewController *)[mainStoryboard     
      instantiateViewControllerWithIdentifier:@"YourViewControllerID"];
    self.window.rootViewController = yourController;
}

return YES;

Upvotes: 0

Alex Zavatone
Alex Zavatone

Reputation: 4323

You'll need an entry for the iPad in your app's info.plist

Look in your Supporting Files group for the info.plist for your app.

You'll see an entry for the iPhone's storyboard, but not one for the iPad.

The iPhone entry should look like this:

Main storyboard file base name

and it should have the name of your iPhone's storyboard (sans file extension) as the string value for it. Something like this:

iPhone-Storyboard

Add a new entry into the pList and enter this string as the key:

Main storyboard file base name (iPad)

Make sure the data type is string.

You can now select the iPad storyboard that you want from the app's General Settings on your Target.

I JUST ran into this as well and thought you'd like a clear explanation and solution.

Sometimes, Xcode is rather maddening, isn't it? Hope this helps.

Upvotes: 0

danielM
danielM

Reputation: 2512

Your code is overriding the default storyboard for the device type. You are grabbing MainStoryboard, instantiating a view controller from it and setting it as the root. This is normally handled by the storyboard itself. It uses the view controller that you have picked as the root. Try removing all of that code to manually set the storyboard.

Check this project on github for an example of storyboard switching without code: https://github.com/danielmackenzie/StoryboardSelection

Xcode project points to each storyboard per device type and the appropriate board is automatically chosen on launch.

Upvotes: 1

Travis
Travis

Reputation: 3369

Your logic is not taking into account your device. AFAIK, there is no method that looks at your naming postfix ("-iPad") and automatically selects the right storyboard file.

To fix it, simply replace the call to instantiate your storyboard with some logic to pick the right one based on device.

UIStoryboard* storyboard;

if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) 
{
    storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard-iPad" bundle:nil];
} else 
{
    storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
}

Upvotes: -1

Related Questions