title: Error with adding subview: not in the window hierarchy
body: <p>//added
  I want to open subview after action didrangebeacons is on. But when it going there there is no any views on screen. Just this error message</p>
  
  <p>Same previous questions but it not helped to my problem. I haven't got any storyboard or xib files, just clear programming.</p>
  
  <p>BeaconViewController: 0x155eb5b0 on UINavigationController: 0x1559bfe0 whose view is not in the window hierarchy!     </p>
  
  <p><strong>AppDelegate.m:</strong></p>
  
  <pre><code>- (void) viewDidAppear {
  
  }
  
  - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  
  DebugLog(@"");
  
  NSLog(@"good1");
  
  
  //and then access the variable by appDelegate.variable
  // Оповещение о том, что надо включить Bluetooth, через минут, через 10 минут, через 8 часов, через неделю
  [NSTimer scheduledTimerWithTimeInterval:60 target:self selector:@selector(timerCalled) userInfo:nil repeats:NO];
  [NSTimer scheduledTimerWithTimeInterval:900 target:self selector:@selector(timerCalled) userInfo:nil repeats:NO];
  [NSTimer scheduledTimerWithTimeInterval:28800 target:self selector:@selector(timerCalled) userInfo:nil repeats:NO];
  [NSTimer scheduledTimerWithTimeInterval:604800 target:self selector:@selector(timerCalled) userInfo:nil repeats:YES];
  // Конец
  
  //Set up Core Location Manager
  self.coreLocation = [[CLLocationManager alloc] init];
  _coreLocation.delegate = self;
  
  // Load any previously registered notifications
  [self loadNotificationRegions];
  
  // Google Analytics
  // Optional: automatically send uncaught exceptions to Google Analytics.
  [GAI sharedInstance].trackUncaughtExceptions = YES;
  // Optional: set Google Analytics dispatch interval to e.g. 20 seconds.
  [GAI sharedInstance].dispatchInterval = 20;
  // Optional: set debug to YES for extra debugging information.
  [GAI sharedInstance].debug = YES;
  // Create tracker instance.
  id &lt;GAITracker&gt; tracker = [[GAI sharedInstance] trackerWithTrackingId:@"UA-42731391-1"];
  
  // Check if the app needs to read the settings from file
  NSString *transition = [[NSUserDefaults standardUserDefaults] stringForKey:@"transitionStyle"];
  
  // Note: this will not work for boolean values as noted by bpapa below.
  // If you use booleans, you should use objectForKey above and check for null
  if (!transition) {
      [self readFromSettingsFile];
  }
  
  self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
  
  // Override point for customization after application launch.
  [[UIButton appearance] setTintColor:[UIColor whiteColor]];
  
  // Remove the shadows of the bar
  [[UINavigationBar appearance] setShadowImage:[[UIImage alloc] init]];
  
  // Set the bar translucent
  
  NSLog(@"good - start uinavig");
  UINavigationController *navController = [[UINavigationController alloc] init];
  navController.navigationBar.barStyle = UIBarStyleBlackTranslucent;
  navController.navigationBar.translucent = true;
  NSLog(@"good - end uinavig");
  
  // Background Color
  if (IS_IOS_GREATER_THAN_OR_EQUAL_TO(@"7")) {
      [[UINavigationBar appearance] setBarTintColor:NAVIGATIONS_VIEWS_BACKGROUND_COLOR];
  } else {
      [[UINavigationBar appearance] setBackgroundImage:[[UIImage alloc] init] forBarMetrics:UIBarMetricsDefault];
      [[UINavigationBar appearance] setBackgroundColor:NAVIGATIONS_VIEWS_BACKGROUND_COLOR];
  }
  
  // Buttons Color
  [[UINavigationBar appearance] setTintColor:[UIColor colorWithRed:255 / 255.0f green:255 / 255.0f blue:255 / 255.0f alpha:1]];
  
  // Back button
  if (IS_IOS_LESS_THAN(@"7")) {
  
      UIImage *buttonBack30 = [[UIImage imageNamed:@"icon_back.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 25, 0, 5)];
      UIImage *buttonBack24 = [[UIImage imageNamed:@"icon_back_landscape.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 25, 0, 5)];
      [[UIBarButtonItem appearance] setBackButtonBackgroundImage:buttonBack30 forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
      [[UIBarButtonItem appearance] setBackButtonBackgroundImage:buttonBack24 forState:UIControlStateNormal barMetrics:UIBarMetricsLandscapePhone];
      [[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(0, -1.5) forBarMetrics:UIBarMetricsDefault];
      [[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(0, -2.0) forBarMetrics:UIBarMetricsLandscapePhone];
      NSMutableDictionary *attributes = [NSMutableDictionary dictionary];
      [attributes setValue:[UIColor colorWithRed:(255 / 255.0f) green:(255 / 255.0f) blue:(255 / 255.0f) alpha:1.0f] forKey:UITextAttributeTextColor];
      [attributes setValue:[UIColor clearColor] forKey:UITextAttributeTextShadowColor];
      [attributes setValue:[NSValue valueWithUIOffset:UIOffsetMake(0.0, 0.0)] forKey:UITextAttributeTextShadowOffset];
      [attributes setValue:[UIFont fontWithName:@"HelveticaNeue" size:16.0f] forKey:UITextAttributeFont];
  
      [[UIBarButtonItem appearance] setTitleTextAttributes:attributes forState:UIControlStateNormal];
  }
  
  // Title Color and Font
  [[UINavigationBar appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
                                                        [UIColor whiteColor], UITextAttributeTextColor,
                                                        [UIFont fontWithName:@"HelveticaNeue-Bold" size:17.0], UITextAttributeFont, nil]];
  
  self.viewController = [[ViewController alloc] init];
  navController.viewControllers = [NSArray arrayWithObject:self.viewController];
  //
  self.window.rootViewController = navController;
  [self.window makeKeyAndVisible];
  
  return YES;
  }
  </code></pre>
  
  <p><strong>and calling:</strong></p>
  
  <pre><code> - (void)locationManager:(CLLocationManager *)manager didRangeBeacons:(NSArray *)beacons inRegion:(CLBeaconRegion *)beaconRegion
      {
      blabla
  
  if(blabla)
                              {
                                  NSLog(@"good - testing - 03.5");
  
                                  BeaconViewController* room = [[BeaconViewController alloc] init];
  
                                  [self.window.rootViewController presentViewController:room
                                                                               animated:YES
                                                                             completion:nil];
                                                                            completion:nil];
  
                                  region.helloMessage = @"привет";
                              }
  </code></pre>
  
  <p><strong>BeaconViewController.m</strong></p>
  
  <pre><code>#import "BeaconViewController.h"
  #import "PageView.h"
  
  @implementation BeaconViewController
  {
      NSUInteger _numPages;
  }
  
  
  
  - (void) vidDidAppear {
  
  }
  
  
  
  - (void)viewDidLoad
  {
      [super viewDidLoad];
  
      _numPages = 2;
  
      self.pagingScrollView.previewInsets = UIEdgeInsetsMake(0.0, 50.0, 0.0, 50.0);
      [self.pagingScrollView reloadPages];
  
      self.pageControl.currentPage = 0;
      self.pageControl.numberOfPages = _numPages;
  
  }
  
  - (void)viewDidAppear:(BOOL)animated {
  
  }
  
  
  - (void)didReceiveMemoryWarning
  {
      [self.pagingScrollView didReceiveMemoryWarning];
  }
  
  #pragma mark - Actions
  
  - (IBAction)pageTurn
  {
      [self.pagingScrollView selectPageAtIndex:self.pageControl.currentPage animated:YES];
  }
  
  #pragma mark - View Controller Rotation
  
  - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
  {
      return YES;
  }
  
  - (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
  {
      [self.pagingScrollView beforeRotation];
  }
  
  - (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
  {
      [self.pagingScrollView afterRotation];
  }
  
  #pragma mark - UIScrollViewDelegate
  
  - (void)scrollViewDidScroll:(UIScrollView *)theScrollView
  {
      self.pageControl.currentPage = [self.pagingScrollView indexOfSelectedPage];
      [self.pagingScrollView scrollViewDidScroll];
  }
  
  - (void)scrollViewDidEndDecelerating:(UIScrollView *)theScrollView
  {
      if ([self.pagingScrollView indexOfSelectedPage] == _numPages - 1)
      {
          _numPages++;
          [self.pagingScrollView reloadPages];
          self.pageControl.numberOfPages = _numPages;
      }
  }
  
  
  
  #pragma mark - MHPagingScrollViewDelegate
  
  - (NSUInteger)numberOfPagesInPagingScrollView:(MHPagingScrollView *)pagingScrollView
  {
      return _numPages;
  }
  
  - (UIView *)pagingScrollView:(MHPagingScrollView *)thePagingScrollView pageForIndex:(NSUInteger)index
  {
      PageView *pageView = (PageView *)[thePagingScrollView dequeueReusablePage];
      if (pageView == nil)
          pageView = [[PageView alloc] init];
  
      [pageView setPageIndex:index];
      return pageView;
  }
  
  @end
  </code></pre>