Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Attempt to present <ViewController:> on <UITabBarController > whose view is not in the window hierarchy

I want a particular tab to be opened at launch time in a tab bar application.I get the warningWarning: Attempt to present <settingsViewController: 0x16e49870> on <UITabBarController: 0x16d25440> whose view is not in the window hierarchy!.

self.tabBarController.selectedIndex = 1;

I tried in DidFinishLaunching

 UITabBarController *tabBarController = (UITabBarController *)self.window.rootViewController;


numpadviewcontroller = [[tabBarController viewControllers] objectAtIndex:0];
settingsviewcontroller = [[tabBarController viewControllers] objectAtIndex:1];
[tabBarController setSelectedIndex:1];

But getting the same warning.I am using storyboards

I tried the code in viewWillAppear,ViewDidLoad also of the first controller of tab bar but i get the same error.

like image 746
Suraj K Thomas Avatar asked Jan 12 '23 11:01

Suraj K Thomas


1 Answers

In both viewWillAppear and viewDidLoad the ViewController's view has not been loaded in the window hierarchy yet. I would try to add the code in viewDidAppear.

like image 166
tanzolone Avatar answered May 16 '23 06:05

tanzolone