2012-10-27 11 views
9

Sto usando il seguente codice nel mio AppDelegate.m per rilevare quale dispositivo l'utente sta utilizzando:carico Storyboard diverso per iPhone 5 @ app start

- (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; 
} 

Ma quando ho costruire l'App del NSLog è mostrato, ma non Storyboard è in arrivo ...

  • il campo principale Storyboard nelle informazioni di distribuzione è vuoto in modo che il codice ha deciso cosa caricare ...

Qualcuno può aiutarmi?

Thx e cordiali saluti dalla Germania

Laurenz :)

+1

qualsiasi motivo è necessario diverse storyboard, dal momento che è possibile passare tra i formati da 3,5 pollici e 4 pollici nell'editor storyboard? – jrturton

+1

Lo switch tra il 3.5 pollici e il 4inch Layout è solo una simulazione, non si è in grado di progettare interfacce diverse in bianco con questo metodo! –

risposta

15

Ecco un modo che ora trovato su un altro post:

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

Ma dove mettere questo codice? –

+1

Ovviamente in AppDelegate.m ;-) –

+0

Ho capito ... Era così ovvio! hahahha –