pdenlinger
pdenlinger

Reputation: 3917

How to set root view controller

I set up an empty app with only an app delegate class, then subclassed a view controller class to create a xib to layout the app and make connections.

But when I tried to run the app on iOS Simulator, I got an error which read: CoinToss[6212:f803] Applications are expected to have a root view controller at the end of application launch Terminating in response to SpringBoard's termination. Program ended with exit code: 0

What do I need to do in order to create a root view controller for the app?

Thank you.

Upvotes: 16

Views: 36714

Answers (4)

jeet.chanchawat
jeet.chanchawat

Reputation: 2595

Applications are expected to have a root view controller

Replace in AppDelegate

 [window addSubview:[someController view]];

to

 [self.window setRootViewController:someController];

Upvotes: 0

user2485971
user2485971

Reputation:

in AppDelegate.m

(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:UIScreen.mainScreen.bounds];



    UIViewController *viewController = // determine the initial view controller here and instantiate it with [storyboard instantiateViewControllerWithIdentifier:];

    self.window.rootViewController = viewController;//making a view to root view
    [self.window makeKeyAndVisible];

    return YES;
}

Upvotes: 25

Ahmed Z.
Ahmed Z.

Reputation: 2337

You need to set 2 things for that..

  1. in AppDelegate.m file: _applicationDidFinishLaunchingWithOptions_

    self.window.rootViewController = self.viewController;

  2. in application.m

    retVal = UIApplicationMain(argc, argv, nil, @"AppDelegate");

Upvotes: 0

Caleb
Caleb

Reputation: 125017

Since you're apparently using .xib files, load your view controller and the set the window's rootViewController property to your view controller in -application:didFinishLaunchingWithOptions:.

Upvotes: 0

Related Questions