0

I checked the various answers here and could not find one which works. I have a regular TabBarController based application. I want to show a login screen at launch. What I did was

  • Subclassed UITabBarController and implemented the following in the viewDidAppear:

    LoginViewController *controller = (LoginViewController *)[[UIStoryboard storyboardWithName:@"Main" bundle: nil] instantiateViewControllerWithIdentifier:@"LoginVC"]; [self presentViewController:controller animated:YES completion:nil];

Once this runs there are 2 things happening : 1. The login view never shows up 2. The log has this : Warning: Attempt to present on whose view is not in the window hierarchy!

What am I missing?

user3570727
  • 10,163
  • 5
  • 18
  • 24
  • Is your new subclass set as the window's rootviewcontroller? – Austen Chongpison Sep 30 '14 at 23:35
  • I updated the storyboard to say that the UITabBarController is MyTabBarController. Yes from application:didFinishLaunchingWithOptions : (lldb) po self.window.rootViewController – user3570727 Sep 30 '14 at 23:36
  • Hmnn.. in the story board it says Tab Bar Controller. If I go to the inspector and check the custom class it says MyTabBarController – user3570727 Sep 30 '14 at 23:40
  • Take a look at the solutions presented here:http://stackoverflow.com/questions/15287678/warning-attempt-to-present-viewcontroller-whose-view-is-not-in-the-window-hiera/15287859#15287859 – Austen Chongpison Sep 30 '14 at 23:41
  • nothing there actually worked.. the only idea i got from there is that the UITabBarController may not be the right place to show the view, as the first view controller in the tabbarcontroller may not be ready, so I moved the code to the first ViewController the TabBarController shows, but that shows : 2014-09-30 16:46:36.753 myapp[45844:3321157] Presenting view controllers on detached view controllers is discouraged . 2014-09-30 16:46:37.329 myapp[45844:3321157] Unbalanced calls to begin/end appearance transitions for . – user3570727 Sep 30 '14 at 23:47
  • I also tried this in the first view controller viewDidLoad [self.tabBarController presentViewController:controller animated:YES completion:nil]; 2014-09-30 16:52:35.173 myapp[45900:3336546] Unbalanced calls to begin/end appearance transitions for . – user3570727 Sep 30 '14 at 23:54
  • Try doing it in viewDidAppear with no animation, and that modal view controller should be the first thing the user sees. – rdelmar Oct 01 '14 at 00:06

1 Answers1

0

rdelmar answer fixed the warning, that is do the presentation in the viewDidAppear. Thanks!

user3570727
  • 10,163
  • 5
  • 18
  • 24