Xcode universal app templates, and overriding didFinishLaunchingWithOptions

4.2k views Asked by At

I'm attempting to build my first universal iOS app using the default Xcode templates for a window-based application - and setting the Device Family to "Universal". (I'm using Xcode 4, but I believe the templates are nearly identical for previous versions of Xcode.)

This creates a shared app delegate, along with specific app delegates for iPhone and iPad.

Since the iPad will need to load a SplitViewController when the app launches, and the iPhone will need to load the RootViewController (a table view) - I decided to try overriding the didFinishLaunchingWithOptions method in the device specific app delegates, like this for the iPhone:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    [super application:application didFinishLaunchingWithOptions:launchOptions];

    RootViewController *rootViewController = (RootViewController *)[_navController topViewController];
    rootViewController.context = [self managedObjectContext];

    [_window addSubview:_navController.view];

    return YES;
}

However, since Xcode places the device specific app delegate files in an "iPhone" or "iPad" group, I get an error saying "RootViewController.h" file not found... despite trying to import it with:

#import "RootViewController.h"

Is there a way to resolve that, or am I going about this the wrong way altogether? I'd rather not move the "RootViewController.h" file into the iPhone group, since I think it will also be used on the iPad.

1

There are 1 answers

1
jlsuttles On BEST ANSWER

You should follow this model: http://www.kotancode.com/2011/04/05/ios-universal-apps/ and you should be importing "RootViewController_iPhone.h"