views:

50

answers:

1

HI all,

In xcode I am trying to load different nib file in case I am using iphone/ipod or ipad.

I have a Define.h file with all enum and constants in it, so I would like to put in there a kind of (obviously wrong because I don't know how to do it):

#if IPHONE  // <-- can I intercept the Active Executable here ?
  #define MY_VIEW @"TableViewIphone.xib"
#else
  #define MY_VIEW @"TableViewIpod.xib"
#endif 

Then in my view controllers which include Define.h

[[NSBundle mainBundle] loadNibNamed:MY_VIEW owner:self options:nil];

I am in need of doing this with device simulator, is there a way to intercept what's in "Active Executable" in xcode and have a specialized set of define ? Are there any other and easier alternatives ?

thanks

+1  A: 

What you want to do is select a xib at run-time, appropriate for the device.

What you are doing is a compile-time selection, which will set the xib to be used for all devices, which is not what you want.

I'm assuming you're building a Universal app, yes?

I prefer to have the device load the appropriate xib when my app is launched by using the proper key in my app's Info.plist file, which is the key NSMainNibFile~ipad. (e.g. I set NSMainNibFile~ipad to MainWindow-iPad... note: no ".xib" bit)

Another alternative is to use the UI_USER_INTERFACE_IDIOM macro:

if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
    // Load iPad xib
}
else
{
    // Load iPhone xib
}
Shaggy Frog
Thanks, don't know if Universal, but the goal is just to display differently for ipad without changing the model behind. I tought that doing this at compile time was better. Otherwise I would have to add lot of "if" statement in the code, or maybe there's an alternative. Also can you be more detailed for the first case ? I am still a newbie :-)
Leonardo
You don't need any "if" statements at all for the first case. My "MainWindow-iPad.xib" has an iPad-specific class set for the Application Delegate (`AppDelegate-iPad`) and contains a view controller specific for the iPad (a `UISplitViewController`). I just set the `NSMainNibFile~ipad` key in my `Info.plist` and away I go. :)
Shaggy Frog
Yes, ok for the very first nib, I just did as you suggested. But if an application has several xib and therefore several controller, I can see no other way rather than writing a new specific controller for the new ipad.xib or using "if else" statement in the existing one.
Leonardo