2014-04-08 70 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