2014-04-08 50 views
1

嗨,大家好,我有一些小问题。所以我在我的项目中使用三个故事板,还有iPhone 4s故事板/ iPhone 5和我为iPad创建的故事板。所以对于选择故事板我使用此代码:如何用iPhone创建iPad故事板还

UIStoryboard * mainStoryboard = nil ; 
CGRect screenBounds = [[UIScreen mainScreen] bounds]; 
if (screenBounds.size.height == 568) { 
    mainStoryboard = [ UIStoryboard storyboardWithName : @ "iPhone5" bundle : nil ] ; 

} else { 
    mainStoryboard = [ UIStoryboard storyboardWithName : @ "iPhone4s" bundle : nil ] ; 

} 
self.window = [ [ UIWindow alloc ] initWithFrame : [ [ UIScreen mainScreen ] bounds ] ] ; 
self.window.rootViewController = [ mainStoryboard instantiateInitialViewController ] ; 
[ self.window makeKeyAndVisible ] ; 

工作完美但不适用于iPad。在此代码后,我的iPad故事板没有看到。如何选择所有故事板的iPad故事板。我了解我的问题,但我找不到解决方案。它是如何创建的?谢谢。

另外我试过这个...但没有。

if ([[UIDevice currentDevice] userInterfaceIdiom] ==UIUserInterfaceIdiomPhone) 
{ 
    UIStoryboard * mainStoryboard = nil ; 

     CGRect screenBounds = [[UIScreen mainScreen] bounds]; 
      if (screenBounds.size.height == 568) { 
      mainStoryboard = [ UIStoryboard storyboardWithName : @ "iPhone5" bundle : nil ] ; 

      } else { 
       mainStoryboard = [ UIStoryboard storyboardWithName : @ "iPhone4s" bundle : nil ] ; 

      } 

} 
else 
{ 
    UIStoryboard *appropriateStoryboard = [self storyboard]; 
    self.window.rootViewController = [appropriateStoryboard instantiateInitialViewController]; 
    return YES; 
    - (UIStoryboard *)storyboard 
    { 
     NSString *storyboardName = @"iPadMyBoard"; 
     if ([self isPad]) { 
      storyboardName = [storyboardName stringByAppendingString:@""]; 
     } 
     return [UIStoryboard storyboardWithName:storyboardName bundle:nil]; 
} 

    -(BOOL)isPad 
    { 
     return (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad); 
    } 

回答

1

您可以使用此代码

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{  
    UIStoryboard *appropriateStoryboard = [self storyboard]; 
    self.window.rootViewController = [appropriateStoryboard instantiateInitialViewController]; 
    return YES; 
} 

- (UIStoryboard *)storyboard 
{ 
    NSString *storyboardName; 
    if ([self isPad]) 
    { 
     storyboardName = @"iPadMyBoard"; 
    } 
    else 
    { 
     if ([self isPhone5]) 
     { 
      storyboardName = @"iPhone5"; 
     } 
     else 
     { 
      storyboardName = @"iPhone4s"; 
     } 
    } 
    return [UIStoryboard storyboardWithName:storyboardName bundle:nil]; 
} 

-(BOOL)isPad 
{ 
    return (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad); 
} 

-(BOOL)isPhone5 
{ 
    CGRect screenBounds = [[UIScreen mainScreen] bounds]; 
    if (screenBounds.size.height == 568){ 
     return YES; 
    } 
    return NO; 
} 
+0

它选择iPad的故事板,但故事板适用于iPhone的 - 不是。 – Genevios

+0

因此,当我选择iPhone 4s例如我从iPad的故事板 – Genevios

+0

我编辑的代码,再次看。 – Erhan