Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
726 HOUR 23: Building Universal Applications Did You Know? The easiest way to target a specific platform in the iOS Simulator is to use the right side of the Scheme menu in Xcode's toolbar. Choose iPad Simulator to force the application to run on the iPad or choose iPhone Simulator to force it to the iPhone. Unfortunately, this approach can get overwhelming if you are producing an app with radically different interfaces for iPhones and iPads. In these cases, it might make more sense to have a separate view controller managing each interface. In our second project, we do exactly that: create an application that looks identical to this one but that has a unique view controller handling interactions depending on the device it is running on. Creating a Universal Application (Take 2) Our second pass at building a universal application will work similarly to what we just built, but with one distinct difference. Instead of using the default universal tem- plate as is, we create a view controller called iPadViewController that is dedicated to managing the iPad's views. We continue to use the default ViewController class for the iPhone. By structuring the project this way, we end up with two unique controllers that can implement interfaces as alike or dissimilar as we want. In addition, we do not need to check to see what type of device we're running on because the correct view con- troller class for the correct device is automatically instantiated when the storyboard is chosen at launch. Setting Up the Project Start the second tutorial the same way as the first: Use the Single View Application with a Device Family setting of Universal to create a new application. Name the new application UniversalToo . Next, we need to create the iPad view controller class that will contain all of our iPad-specific UI management. Adding an iPad View Controller Our application already has a single view controller subclass ( ViewController ), but we need another. To create a new UIViewController subclass, choose File, New File from the menu. When prompted, navigate to the iOS Cocoa Touch category and choose the UIViewController subclass icon, as shown in Figure 23.7. Then click Next.