Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make iPhone and iPad version of an app?

I am trying to make an app which works on both iPhone and iPad. I am looking how to make an interface compatible on both. When the app loads I am displaying a table view. How can I load different nibs based on device? I am using this to switch between nibs.

if ([[UIDevice currentDevice] respondsToSelector:@selector(userInterfaceIdiom)]) 
    {
        if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) 
        {
            device = @"iPad";
        }
        else 
        {
            device = @"iPhone";
        }

    }

But in MainWindow.xib it says view is loaded from the view controller for iPhone. Can I make this dynamic based on device? ie I want to show from the start of app different nibs based on device. Thanks.

like image 435
Nikil Avatar asked Feb 05 '11 18:02

Nikil


2 Answers

Actually, Apple does all this automatically, just name your NIB files:

MyViewController~iphone.xib // iPhone
MyViewController~ipad.xib // iPad

and load your view controller with the smallest amount of code:

[[MyViewController alloc] initWithNibName:nil bundle:nil]; // Apple will take care of everything
like image 167
Adam Avatar answered Oct 17 '22 04:10

Adam


You can do that in a similar way:

if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad){
    mainMenu = [[MainMenu alloc] initWithNibName:@"MainMenuiPad" bundle:nil]; 
}else{  
    mainMenu = [[MainMenu alloc] initWithNibName:@"MainMenu" bundle:nil]; 
}
like image 27
hanno Avatar answered Oct 17 '22 03:10

hanno