user2003416
user2003416

Reputation: 159

Application running with RootviewController error- Applications are expected to have a root view controller at the end of application launch

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.
    self.viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
    self.window.rootViewController = self.viewController;
    [self.window makeKeyAndVisible];
    return YES;
}

I do not know what is wrong with this method.I just created a new project and run it.It showing Applications are expected to have a root view controller at the end of application launch

Upvotes: 0

Views: 719

Answers (1)

bitmapdata.com
bitmapdata.com

Reputation: 9600

If you have a MainWindow.xib.

remove below line. do not remove MainWindow.xib

self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
    self.window.rootViewController = self.viewController;
    [self.window makeKeyAndVisible];
    return YES;
}

enter image description here

OR

do not remove above line. remove MainWindow.xib and Project Summary Main Interface set null.

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    self.viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
    self.window.rootViewController = self.viewController;
    [self.window makeKeyAndVisible];
    return YES;
}

enter image description here

Upvotes: 3

Related Questions