Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting windows root view controller not working

I am trying to change the view controller from my AppDelegate like this:

UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
UIViewController *vc = [storyBoard instantiateInitialViewController];
NSLog(@"ViewController: %@",vc);
self.window.rootViewController = vc;
NSLog(@"ViewController: %@",self.window.rootViewController);

However the screen remains black. Here are my NSLogs:

ViewController: MyViewController
ViewController: (null)
like image 487
Abdullah Shafique Avatar asked Jul 13 '26 19:07

Abdullah Shafique


1 Answers

It seems your self.window is nil. Are you sure you did not forget to create it?

self.window = [ [ UIWindow alloc ] initWithFrame:[ [ UIScreen mainScreen ] bounds ] ];
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
like image 148
Avt Avatar answered Jul 15 '26 11:07

Avt



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!