Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Apple now provides you with a default mechanism to separate your code between iPhone and iPad while in the same project.</p> <p>In Xcode 4, when you create a new "Window-based Application" or "View-based Application", you are given the option to select a "Device Family". If you select "Universal" for this option, Xcode will create 3 app delegates.</p> <p>First, a main app delegate:</p> <pre><code>YourAppNameAppDelegate : NSObject &lt;UIApplicationDelegate&gt; </code></pre> <p>and two other app delegates (placed in separate groups) that are subclasses of "YourAppNameAppDelegate":</p> <pre><code>YourAppNameAppDelegate_iPhone : YourAppNameAppDelegate YourAppNameAppDelegate_iPad : YourAppNameAppDelegate </code></pre> <p>When you run your app with either the iPhone or iPad simulator (or device), the application will automatically use either the _iPhone or _iPad app delegate subclass based on the device chosen.</p> <p>If you override application:didFinishLaunchingWithOptions: method in each subclass, you will see this working:</p> <pre><code>// In YourAppNameAppDelegate_iPhone.m - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { NSLog(@"iPhone App Delegate"); return [super application:application didFinishLaunchingWithOptions:launchOptions]; } // In YourAppNameAppDelegate_iPad.m - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { NSLog(@"iPad App Delegate"); return [super application:application didFinishLaunchingWithOptions:launchOptions]; } </code></pre> <p>This gives you a starting point where you can alter program flow based on the device the user is on. For instance by instantiating one of the subclasses of your main view controller (as described below).</p> <p>As you add new view controllers to your project, you should continue with this paradigm by creating one generic controller superclass, and an iPhone/iPad specific subclass. Note that the generic superclasses should not have nib files associated with them, while the subclasses should each have their own separate nib.</p> <p>That way you can break your code between the three classes, keeping things that are platform independent in the superclass - for instance some properties, methods, IBOutlets, and IBActions - and place the platform specific implementations into either subclass.</p>
 

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