Pergunta

I am working on Storyboard. I have 2 story board for iPhone & iPad. 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.

Foi útil?

Solução

Try this one.

In your AppDelegate method first define this one:

#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

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

I think this will helps you :)

Outras dicas

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):

Deployment Info -> Main Interface -> storyboardname Or Programatically you can differ by:

  #define interfaceType    UI_USER_INTERFACE_IDIOM()

    #define IPAD     UIUserInterfaceIdiomPad

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

    } else {

    `enter code here`
    }
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top