Note that there are some explanatory texts on larger screens.

plurals
  1. PONon-universal iPhone app build automatically loads iPad nibs when run on iPad
    primarykey
    data
    text
    <p>My app started life as an iPad-only app. Now I am converting it into a smaller version suitable for the iPhone. I am using the same codebase, and many of the controllers don't actually need to change much - just the views need to be remade to suit the smaller screen. This is not a universal app, as some of the features differ between iPad and iPhone versions, and the price points in the App Store are very different.</p> <p>I have added separate target with the device family set to iPhone. The original target has this set to iPad. </p> <p>I remade a bunch of nibs with the filenames following the format <code>view~iphone.xib</code>, and when I run the iPhone build on an iPhone, these are correctly loaded instead of the original iPad ones (which have filenames in the format <code>view.xib</code>).</p> <p>The problem is when I run the <strong>iPhone</strong> build on an iPad. As you'd expect for an iPhone app, it runs in that little iPhone window (that can be doubled to 2x). But the nibs that are loaded are the <strong>iPad</strong> nibs which obviously don't fit or resize well for the iPhone sized display. I don't understand why iOS wouldn't automatically load the iPhone versions. If I test <code>UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad</code>, it returns false, so it knows it is running in iPhone mode!</p> <p>Given that I can't stop customers from running the iPhone app on an iPad, I want to make it work correctly. I've tried a few things but they do not seem right:</p> <ul> <li>Changing the code to <code>[[MyViewController alloc] initWithNibName:@"MyView~iphone" bundle:nil];</code> will load the correct nib, but that means I would have to put conditional code around all of the locations where a nib name is specified - this is a big app so there are a lot, and this could be error-prone in the future when I or another developer forgets to do this in new code.</li> <li>Renaming all of the <code>~iphone</code> nibs to have identical filenames to the iPad versions (i.e. <code>view.xib</code>), moving them into a separate directory (so that they don't collide with the names of the originals) and re-adding them back to the project but only included in the iPhone target (and not the iPad target), and unticking the original iPad nibs from the iPhone target (but still included on the iPad target) will cause the correct nibs to be loaded at runtime (because the "wrong" nibs are no longer in the bundle for each build), regardless of the naming. Note that if I leave the filename as <code>view~iphone.xib</code>, then when the iPhone build runs on an iPad, there is an exception upon trying to load that nib: <code>Could not load NIB in bundle</code>. The identical filenames make this method pretty unpleasant and at first glance it's not obvious what's going on. </li> <li>Renaming the original xib to <code>view~ipad.xib</code> (with the iPhone nib as <code>view~iphone.xib</code>) still causes the iPad nib to be loaded when running the iPhone build on the iPad.</li> </ul> <p>There must be a better way than either of these? Why is the wrong (iPad) nib loaded when the device clearly knows it is running an iPhone app?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload