2013-02-25 2 views
1

Je rencontre des problèmes avec la taille de l'écran de l'iPhone 5. J'ai créé deux fichiers xib (MainWindow.xib et MainWindowiPhone5.xib) pour que mon application soit compatible avec les deux tailles d'écran.Comment ajouter deux fichiers xib à mon AppDelegate pour prendre en charge les tailles d'écran de l'iPhone?

J'ai essayé de le coder sur mon AppDelegate.m, mais cela ne fonctionne pas.

Voici mon code AppDelegate:

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

if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone){ 
    UIStoryboard *storyBoard; 

    CGSize result = [[UIScreen mainScreen] bounds].size; 
    CGFloat scale = [UIScreen mainScreen].scale; 
    result = CGSizeMake(result.width * scale, result.height * scale); 

    if(result.height == 1136){ 
     storyBoard = [UIStoryboard storyboardWithName:@"MainWindowiPhone5" bundle:nil]; 
     UIViewController *tabBarController = [storyBoard instantiateInitialViewController]; 
     [self.window.rootViewController = self.tabBarController]; 
    } 
} 

return YES; 



self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 



// Override point for customization after application launch. 
// Set the tab bar controller as the window's root view controller and display. 
self.window.rootViewController = self.tabBarController; 
tabBarController.moreNavigationController.navigationBar.tintColor = [UIColor blackColor]; 
[self.window makeKeyAndVisible]; 
return YES; 

}

Comment puis-je obtenir à la fois de travailler sur xib mon code?

Aidez-nous s'il vous plaît. Merci.

Répondre

2

Conditions devrait être ::

Pour iPhone 4S ou plus-écran:

if ([[UIScreen mainScreen] bounds].size.height == 480) 
{ 
    ---- Your Code ---- 
} 

Pour écran iPhone-5:

if ([[UIScreen mainScreen] bounds].size.height == 568) 
{ 
    ---- Your Code ---- 
} 

Si tout va bien ... Peut-être vous aider .
Merci.

+0

Merci pour la réponse. J'ai essayé d'implémenter le code et j'ai le ** Thread 1: signal SIGABRT ** erreur 'int retVal = UIApplicationMain (argc, argv, nil, nil);'. Dois-je changer quelque chose pour supporter les fichiers ** xib **? – esierr1

+0

Voici le code: 'if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {if ([UIScreen mainScreen] .bounds.size.height == 568) {storyBoard = [UIStoryboard storyboardWithName: @ Paquet" MainWindowiPhone5 ": néant ] } else {if ([[UIScreen mainScreen]]] .size.height == 480) {storyBoard = [UIStoryboard storyboardWithName: @ "Paquet MainWindow": nil]; 'Merci pour votre aide! – esierr1

+1

Vous n'avez pas besoin de prendre 2 storyboards différents. Vous ne pouvez utiliser qu'un seul storyboard et conserver toutes les vues automatiquement. –

0

Ajoutez ce code dans votre initialisation:

if([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone){ 
    if([UIScreen mainScreen].bounds.size.height == 568.0)){ 
      //move to your iphone5 storyboard 
      [UIStoryboard storyboardWithName:(NSString *) bundle (NSBundle *)]; 
    } 
    else{ 
      //move to your iphone4s storyboard 
      [UIStoryboard storyboardWithName:(NSString *) bundle (NSBundle *)]; 
    } 
} 
+0

Merci pour votre réponse. J'ai ajouté le code suggéré, a lancé l'application et il jette le suivant ** Thread 1: signal SIGABRT ** 'int retVal = UIApplicationMain (argc, argv, nul, nul);' Y a-t-il quelque chose que je fais mal ici? Merci @Sun Tzu – esierr1

+0

Voici le code: 'si ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) { if ([UIScreen mainScreen] s == 568,0) {// déplacer à votre story-board iPhone5 storyBoard = [UIStoryboard storyboardWithName: @ bundle "MainWindowiPhone5": néant]; } // passer à votre storyboard iphone4s storyBoard = [UIStoryboard storyboardWithName: @ "MainWindow" bundle: nil]; '** MainWindow ** et ** MainWindowiPhone5 ** sont des fichiers xib. Merci. – esierr1

Questions connexes