Sunday, September 25, 2011

applications are expected to have a root view controller at the end of application launch

If you met this error when you developing ios app, you can refer to this link.

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]];

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:

cupsofcocoa said...

Thanks for the referral!

Anonymous said...

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.

Anonymous said...

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

Anonymous said...

Update: on the other hand, my test app now no longer responds to touch events.