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.
Try this in your
Info.plist
:Main nib file base name [
NSMainNibFile
]: MainWindow_iPhoneMain nib file base name (iPad) [
NSMainNibFile~ipad
]: MainWindow_iPadI hope this helps you.
Actually, Apple does all this automatically, just name your NIB files:
and load your view controller with the smallest amount of code:
You can do that in a similar way:
For making universal app,
1-set target family in info build tab for app as iPhone/iPad.
2- Delete window from main window.
3- Add two xib one for iPhone and one for iPad(by selecting iPad xib).
4- make appDelegate class as controller file for these xib's.
5- Add window on these xibs and view controller or navigation controller and by IB Inspector set load nib name and controller file here which one is your first view.
6- And then make differnet xib for iPad and iPhone which having tableview or other controls.
7-Make single contoller file or different controler file for different device for same you need to check the device by this if else condition
8-Now you need to load xib in appDelegate class in method didFinishL--