【问题标题】:How to create iPad storyboard with iPhone also如何也用 iPhone 创建 iPad 故事板
【发布时间】:2014-05-20 20:55:37
【问题描述】:

大家好,我有一些小问题。所以我在我的项目中使用了三个故事板,有 iPhone 4s 故事板/iPhone 5,我也为 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);
    }

【问题讨论】:

    标签: xcode ipad storyboard uistoryboard


    【解决方案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;
    }
    

    【讨论】:

    • 它选择 iPad 故事板,但选择 iPhone 故事板 - 不是。
    • 因此,例如,当我选择 iPhone 4s 时,我会从 iPad 上获取故事板
    猜你喜欢
    • 1970-01-01
    • 2014-11-22
    • 1970-01-01
    • 2013-11-16
    • 2015-09-20
    • 1970-01-01
    • 1970-01-01
    • 2016-08-10
    • 2012-01-17
    相关资源
    最近更新 更多