Question

Im getting this warning "Application is expected to have a root view controller at the end of application launch". Ive read all the other answers and I know why its doing it, but im not sure how to get around it.

I have the following code in my viewDidLoad that is causing the error

//animated header that displays errors over status bar
self.dropdown = [[UIWindow alloc] initWithFrame:CGRectMake(0, -20, 320, 20)];
self.dropdown.backgroundColor = [UIColor redColor];
self.label = [[UILabel alloc] initWithFrame:self.dropdown.bounds];
self.label.textAlignment = NSTextAlignmentCenter;
self.label.font = [UIFont systemFontOfSize:12];
self.label.backgroundColor = [UIColor clearColor];
[self.dropdown addSubview:self.label];
self.dropdown.windowLevel = UIWindowLevelStatusBar;
[self.dropdown makeKeyAndVisible];
[self.dropdown resignKeyWindow];

//needed to hide empty cells at the end of table view.
self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];

If i put that code in viewWillAppear, i dont get the error. THe problem is I dont want it there. I want it in view did load so it only runs once. Can I just ignore the warning, or can I manually set the root in my app delegate or something. I really want to keep it in view did load. Im using storyboards.

Thanks

Was it helpful?

Solution 2

I don't know why adding another window like this causes this error, when the storyboard creates the root view controller (for the main window that is), but you can suppress it by moving all the code to a separate method and calling it with a slight delay (using performSelector:withObject:afterDelay:) from viewDidLoad.

OTHER TIPS

Issue is you didn't specified any view controller as the root view controller of the window you created.

Just set it like:

self.dropdown.rootViewController = yourViewController;

Suggestion:

Don't use multiple windows in an application. It is better to use only one window in your application and multiple view controllers and views. I saw an issue in my career, issue was one of my colleague used multiple windows for displaying different contents instead of view controller, Without proper handling the application crashed 10 times in a minute!!!.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top