damienbrz
damienbrz

Reputation: 1806

Present Modal View from UITabBarController

I have generated a new Tabbed Application using storyboards.

So far I have

TabBarController -> FirstViewController -> SecondViewController -> ModalViewController

I'm trying to open the modal view before showing the tabBarController. I added the following code on the AppDelegate.m

showModalView is called from application:didFinishLaunchingWithOptions:;

- (void)showModalView
{
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
    GSLoginViewController *loginView = [storyboard instantiateViewControllerWithIdentifier:@"loginView"];
    [loginView setModalPresentationStyle:UIModalPresentationFullScreen];
    [self.window.rootViewController presentViewController:loginView animated:YES completion:NULL];
}

And here the output I have:

Warning: Attempt to present <ModalViewController: 0x93670d0> on 
<UITabBarController: 0x935d170> whose view is not in the window hierarchy!

Upvotes: 0

Views: 4450

Answers (1)

Suraj K Thomas
Suraj K Thomas

Reputation: 5883

You are getting this because your Appdelegate don't know that tabbarcontroller is your root view.You should try something like this.

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

and add your code accordingly.The thing is that you should let the app delegate know tabbarcontroller is the rootviewcontroller.

Upvotes: 5

Related Questions