Using Xcode 4.2, my app runs in iOS 5.0 simulator. It runs on a 3G iPhone with iOS 4.2.1. It does not run on an iPod with iOS 3.1.3.
This is boilerplate code I got from any number of tutorials, but on the iOS 3.1.3 device, after displaying my Default.png, this line fails:
self.window.rootViewController = self.viewController;
with ‘Unrecognized selector sent to instance’ in my ykAppDelegate.m here:
#import "ykAppDelegate.h"
#import "ykViewController.h"
@implementation ykAppDelegate
@synthesize window;
@synthesize viewController;
#pragma mark -
#pragma mark Application lifecycle
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
// Set the view controller as the window's root view controller and display.
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
return YES;
}
With a more than cursory glance at the code, I notice viewController isn’t apparently instantiated (except for @synthesize); it’s just declared in my ykAppDelegate.h:
#import <UIKit/UIKit.h>
@class ykViewController;
@interface ykAppDelegate : NSObject <UIApplicationDelegate> {
UIWindow *window;
ykViewController *viewController;
}
@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet ykViewController *viewController;
@end
Is there a small tweak I can make so this will work in iOS 3.1?
In pre-iOS5 operating systems UIWindow doesn’t have a property named ‘rootViewController’. An idiomatic solution is to simply add the view controller’s view as a subview to your application’s key window: