Zack Shapiro
Zack Shapiro

Reputation: 6998

Setting UIWindow in AppDelegate without Storyboards

I'm working on setting up a basic app without storyboards. I removed the storyboards line in Info.plist and I've set the following in my didFinishLaunchingWithOptions.

When I build and run, I get a simulator with a black screen rather than a full-screen of red.

My UIViewController class doesn't have anything in it other than the boilerplate that Xcode creates on creating a new project

UIWindow * window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
[window setBackgroundColor:[UIColor redColor]];
[window setRootViewController:[[ViewController alloc] init]];
[window makeKeyAndVisible];

Any idea what I'm doing wrong here? Thanks

Upvotes: 0

Views: 182

Answers (1)

Abdelahad Darwish
Abdelahad Darwish

Reputation: 6067

use self.window not create new window

self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    [self.window setBackgroundColor:[UIColor redColor]];
    [self.window setRootViewController:[[ViewController alloc]init]];
    [self.window makeKeyAndVisible];

Upvotes: 2

Related Questions