1

I keep getting the warning

Application windows are expected to have a root view controller at the end of application launch

Ive been looking for a fix but all the solutions I found matched my code. Thanks in advance its probably something simple but i've been stuck on it for awhile now.

AppDelegate.m

self.rootController = [[UITabBarController alloc] init];

DownloadTableView *view2 = [[DownloadTableView alloc] init];
view2 = [[UIStoryboard storyboardWithName:@"DownloadTableView" bundle:nil] instantiateViewControllerWithIdentifier:@"Download"];

TableViewController *view3 = [[TableViewController alloc] init];
view3 = [[UIStoryboard storyboardWithName:@"TableViewController" bundle:nil] instantiateViewControllerWithIdentifier:@"table"];

appWebView = [[WebViewController alloc] init];

view3.tabBarItem.title = @"Documents";
appWebView.title = @"Browser";
view2.title = @"Downloads";

self.rootController.viewControllers = [NSArray arrayWithObjects:appWebView, view2, view3,  nil];
self.window.rootViewController = _rootController; 

appWebView.tabBarItem.image = [UIImage imageNamed:@"Browser.png"];
view2.tabBarItem.image = [UIImage imageNamed:@"Download.png"];

_window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// [_window addSubview:_rootController.view];
[_window makeKeyAndVisible];
nickivey
  • 173
  • 2
  • 17
  • Which method are you implementing with the code above? Why are you setting the root view controller twice? Why are you unnecessarily adding the controller's view as a subview after setting it as the root controller (see the documentation for `rootViewController`)? – Jonah Jun 25 '14 at 06:47
  • I cleaned the code up and edited my post I am still getting the warning though – nickivey Jun 25 '14 at 18:56
  • Well now you create a new window, never set its root view controller, and then make it the key window. It shouldn't be surprising that this warns you the root view controller has not been set. – Jonah Jun 25 '14 at 19:45

3 Answers3

0

Few lines seems to be redundant which might cause issue, pointed o -

self.rootController = [[UITabBarController alloc] init];

DownloadTableView *view2 = [[DownloadTableView alloc] init];
view2 = [[UIStoryboard storyboardWithName:@"DownloadTableView" bundle:nil] instantiateViewControllerWithIdentifier:@"Download"];

TableViewController *view3 = [[TableViewController alloc] init];
view3 = [[UIStoryboard storyboardWithName:@"TableViewController" bundle:nil] instantiateViewControllerWithIdentifier:@"table"];

view3.tabBarItem.title = @"Documents";

appWebView = [[WebViewController alloc] init];
appWebView.title = @"Browser";
appWebView.tabBarItem.title = @"Browser";

view2.title = @"Downloads";
self.rootController.viewControllers = [NSArray arrayWithObjects:appWebView, view2, view3,  nil];

self.window.rootViewController = self.rootController; <-----

appWebView.tabBarItem.image = [UIImage imageNamed:@"Browser.png"];
view2.tabBarItem.image = [UIImage imageNamed:@"Download.png"];

_window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
[_window addSubview:_rootController.view]; <-------
[_window makeKeyAndVisible];
rishi
  • 11,779
  • 4
  • 40
  • 59
0

Is all this code called in

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
method? Is _window field connected to window property?

P.S. There are a lot of useless and weird lines, as well.

Artem Stepanenko
  • 3,423
  • 6
  • 29
  • 51
  • Yes thats all in didFinishLaunchingWithOptions @property (readwrite, strong, nonatomic) UIWindow *window; is in the header – nickivey Jun 25 '14 at 18:49
0

Figured it out this morning when I woke up

_window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

Was unnecessary and was conflicting with the tab bar

nickivey
  • 173
  • 2
  • 17