3

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.

BenMorel
  • 34,448
  • 50
  • 182
  • 322
user3631436
  • 459
  • 2
  • 5
  • 10
  • How is defined `loStoryboard`? – Larme May 13 '14 at 08:04
  • Why do you want to differentiate? The correct storyboard will automatically be loaded. Also, `loStoryboard` will be nil. Your controller should be able to handle both the iPad and the iPhone storyboard without ugly `if-else` blocks. If you really need to check the device, use this: http://stackoverflow.com/questions/10167221/ios-detect-if-user-is-on-an-ipad – Marc May 13 '14 at 08:04
  • Your code IS working. It does exactly what you asked for. It instanticates the storyboard based on Main_iPhone regardless whether the app is running on an iPhone or iPad. I suggest to go for Muhammet's suggestion. Or David's which is a bit more mature. – Hermann Klecker May 13 '14 at 09:25

3 Answers3

6

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

Soumya Ranjan
  • 4,817
  • 2
  • 26
  • 51
0

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
}
0

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`
    }
Mohit Jethwa
  • 613
  • 2
  • 6
  • 14