Basically, 2 steps.
1st step, add a RootViewController property in AppDelegate.h.
Add this line before AppDelegate declaration.
@class RootViewController;
Add this line after AppDelegate declaration.
@property (nonatomic, retain) RootViewController *rootViewController;
2nd step, init a RootViewController instance and assign it to the window's root view controller, in didFinishLaunchingWithOptions method.
_rootViewController = [[RootViewController alloc] init];
[[self window] setRootViewController: [self rootViewController]];
[[self window] setRootViewController: [self rootViewController]];
After adding, it would be like this:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.backgroundColor = [UIColor whiteColor];
_rootViewController = [[RootViewController alloc] init];
[[self window] setRootViewController: [self rootViewController]];
[self.window makeKeyAndVisible];
return YES;
}
4 comments:
Thanks for the referral!
Hi, thanks for the tips. Following your suggestion I got compile time linker errors regarding "RootViewController".
Changing the class name to "UIViewController" in the header and implementation files resolved the issue and got rid of the annoying
"Applications are expected to have a root view controller at the end of application launch"
debugger warning.
Cheers.
Clarification:
I changed "RootViewController" to "UIViewController" in:
1) the "@property" line of the header file
2) the method body of the implementation file.
I left the line "@class RootViewController;" as is in the header file.
I'm still very much a newbie trying to work through an iOS 4.x book using iOS 5 tools, so still not quite sure what I'm doing... :p
Update: on the other hand, my test app now no longer responds to touch events.
Post a Comment