2012-10-27 1 views
9

ich den folgenden Code verwende in meinem AppDelegate.m zu erkennen, welches Gerät den Benutzer verwendet:laden verschiedene Storyboard für iPhone 5 @ app starten

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 

    if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) 
    { 
     CGSize result = [[UIScreen mainScreen] bounds].size; 
     if(result.height == 480) 
     { 
      NSLog(@"iPhone 3,5 Inch"); 

      [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone" bundle:nil]; 



     } 
     if(result.height == 568) 
     { 
      NSLog(@"iPhone 4 Inch"); 
      [UIStoryboard storyboardWithName:@"iPhone5-storyboard" bundle:nil]; 
     } 
    } 

    return YES; 
} 

Aber wenn ich die App bauen die NSLog ist gezeigt, aber kein Storyboard aufkommt ...

  • das Hauptstoryboard-Feld in der Deployment-Info ist leer, so dass der Code, was entschieden laden zu ...

Kann mir jemand helfen?

Thx und beste Grüße aus Deutschland

Laurenz :)

+1

Gibt es Gründe, Sie verschiedene Storyboards benötigen, da Sie wechseln zwischen 3,5 Zoll und 4 Zoll Layouts im Storyboard-Editor? – jrturton

+1

Der Switch zwischen dem 3,5-Zoll- und dem 4-Zoll-Layout ist nur eine Simulation, Sie können verschiedene Interfaces nicht mit dieser Methode entwerfen! –

Antwort

15

Hier ist eine Art, wie ich jetzt auf einem anderen Posten gefunden:

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


     CGSize iOSDeviceScreenSize = [[UIScreen mainScreen] bounds].size; 
     UIViewController *initialViewController = nil; 
     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 *iPhone35Storyboard = [UIStoryboard storyboardWithName:@"Storyboard_iPhone35" bundle:nil]; 

      // Instantiate the initial view controller object from the storyboard 
      initialViewController = [iPhone35Storyboard instantiateInitialViewController]; 
     } 

     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 *iPhone4Storyboard = [UIStoryboard storyboardWithName:@"Storyboard_iPhone4" bundle:nil]; 

      // Instantiate the initial view controller object from the storyboard 
      initialViewController = [iPhone4Storyboard 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; 

    } 
+0

Aber wo diesen Code zu setzen? –

+1

Natürlich in der AppDelegate.m ;-) –

+0

habe ich herausgefunden ... Es war so offensichtlich! hahahha –