简体   繁体   English

在iOS中区分iPhone和iPad故事板

[英]Differentiate between iPhone & iPad Storyboard in iOS

I am working on Storyboard . 我正在处理Storyboard I have 2 story board for iPhone & iPad. 我有iPhone和iPad的2层板。 So my question is how can I differentiate between these 2 interfaces. 所以我的问题是如何区分这两个接口。

I am share my code what I did: 我和我的代码分享了我的代码:

// I am writing this code in AppDelegate Method.

UIStoryboard *loStoryboard ;
if (loStoryboard == [UIStoryboard storyboardWithName:@"Main_iPhone" bundle:nil])
{
  // iPhone  .....
}
else
{
  // iPad....
} 

But it's not working. 但它不起作用。

Try this one. 试试这个吧。

In your AppDelegate method first define this one: 在你的AppDelegate方法中,首先定义这个:

#define IPHONE_STORYBOARD_NAME  @"Main_iPhone";
#define IPAD_STORYBOARD_NAME    @"Main_iPad";

Then declare this method: 然后声明这个方法:

+ (NSString *)storyboardName
{
   if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
       return IPHONE_STORYBOARD_NAME;
   } else {
       return IPAD_STORYBOARD_NAME;
   }
}

Where you want call this storyboardName method 你想在哪里调用这个storyboardName方法

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:[AppDelegate storyboardName] bundle:nil];

I think this will helps you :) 我想这会对你有所帮助:)

You don't need to differentiate interfaces. 您不需要区分接口。 This code will return you, which device working: 此代码将返回您,哪个设备正常工作:

if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
        //Ipad
}
else
{
        //Ipod-Iphone
}

You don't need to differentiate scoreboards.We only differentiate in xcode(which scoreboard for which interface): 您不需要区分记分板。我们只区分xcode(哪个界面的记分板):

Deployment Info -> Main Interface -> storyboardname Or Programatically you can differ by: 部署信息 - >主界面 - > storyboardname或者以编程方式,您可以通过以下方式区分:

  #define interfaceType    UI_USER_INTERFACE_IDIOM()

    #define IPAD     UIUserInterfaceIdiomPad

    if ( interfaceType == IPAD ) {
    /* do for iPad. */

    } else {

    `enter code here`
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM