2

I am building a Universal iOS app. I have several buttons on the main view which load other view controllers. I have set up a "Main.storyboard" and an "iPad storyboard.storyboard". I have made two views in the "main" and the "iPad". On the "Main" I have set the Storyboard ID's to "FirstCar" and FirstPlayer". On the "iPad" I have set them to "FirstCarPad" and FirstPlayerPad". In the General settings I have designated the app as Universal and set the "Main" as the storyboard for the iPhone and the "iPad" for the iPad.

I am using the following code to launch the view controllers in the storyboards from the initial view.

if([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone){
   int height = [UIScreen mainScreen].bounds.size.height;

    if (height == 568.0) {

        UIStoryboard *sb = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
        UIViewController *vc = [sb instantiateViewControllerWithIdentifier:@"FirstCar"];

        [self presentViewController:vc animated:YES completion:NULL];     }

}
else if([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad){
    UIStoryboard *sb = [UIStoryboard storyboardWithName:@"ipad storyboard" bundle:nil];
    UIViewController *vc = [sb instantiateViewControllerWithIdentifier:@"FirstCarPad"];

    [self presentViewController:vc animated:YES completion:NULL];  }

When I tap the first button that accesses the "FirstCar" and "FirstCarPad" ViewControllers everything works fine but When I tap the second button that accesses the "FirstPlayer" and "FirstPlayerPad" viewControllers the app crashes with this

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Storyboard () doesn't contain a view controller with identifier 'FirstPlayerPad''

but I have the viewControllers set up the exact same with the Storyboard ID

I am about to tear my hair out.

Can anybody help me out.

Ekta Padaliya
  • 5,743
  • 3
  • 39
  • 51
user1114881
  • 731
  • 1
  • 12
  • 25
  • If you can target iOS 8+, consider using one storyboard and size classes. – dasdom Jul 04 '16 at 07:18
  • I can access size iOS 8+ but when I use auto layout my app doesn't work correctly. I am using motion manager and it keeps resetting things so that when I move an object it returns it to the original position. I wouldn't think this should be that hard though. – user1114881 Jul 04 '16 at 14:39

1 Answers1

0

To get this to work I duplicated the Main.storyboard in the finder renaming it Main-iPad.storyboard then added it to the project. I then right clicked on the new storyboard and chose Open Source. This showed the storyboard as code and I changed targetRuntime="iOS.CocoaTouch" to targetRuntime="iOS.CocoaTouch.iPad". I then right clicked it again but chose Open Storyboard. With the settings set to "Universal" and Main-iPad.storyboard selected as the iPad's storyboard everything works fine. I just have to resize and reposition the elements in each iPad view. Time consuming but worth it. Hope this can be helpful anybody else. I wish when you reconfigured to iPad from iPhone it resized and repositioned the elements in the views but Oh well.

user1114881
  • 731
  • 1
  • 12
  • 25