title: Modal view controller not in the window hierarchy
body: <p>The App I'm trying to do has a tabbar controller.</p>
  
  <p>When the App starts, I'm getting the user location in the AppDelegate and when I've got the accuracy I need the AppDelegate sends an NSNotification to my App's starting page (index 0 of the tab bar controller).</p>
  
  <p>Upon receiving the notification, this view tries to send an email with the user coordinates and other data, but as soon as the MFMailComposeViewController is presented I get the following error: </p>
  
  <pre><code>Warning: Attempt to present &lt;MFMailComposeViewController: 0x98a0270&gt; on &lt;UITabBarController: 0x988c630&gt; whose view is not in the window hierarchy!
  </code></pre>
  
  <p>What am I missing?</p>
  
  <p>Thanks.</p>
  
  <p>EDIT: adding some code...</p>
  
  <p>This is what I've got in my AppDelegate.m:</p>
  
  <pre><code>- (void) locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
  NSUserDefaults *phoneNumbers = [NSUserDefaults standardUserDefaults];
  NSDate *eventDate = newLocation.timestamp;
  NSTimeInterval howRecent = [eventDate timeIntervalSinceNow];
  if (abs(howRecent) &lt; 10.0) {
      [self locationUpdate:newLocation];
      smsLoc = newLocation;
      if ([[phoneNumbers objectForKey:@"sendSMS"] isEqualToString:@"yes"]) {
          [[NSNotificationCenter defaultCenter] postNotificationName:@"sendSMS" object:nil];
      } else if ([[phoneNumbers objectForKey:@"sendEmail"] isEqualToString:@"yes"]) {
          [[NSNotificationCenter defaultCenter] postNotificationName:@"sendEmail" object:nil];
      }
  
  }
  }
  </code></pre>
  
  <p>Then, in my first view controller I have:</p>
  
  <pre><code>- (void)viewDidLoad
  {
  [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(sendSMS:) name:@"sendSMS" object:nil];
  [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(sendEmail:) name:@"sendEmail" object:nil];
  }
  </code></pre>
  
  <p>And at the end, the selector for "sendSMS" (the other is pretty similar):</p>
  
  <pre><code>- (void)sendSMS: (NSNotification *)notification {
  NSUserDefaults *phoneNumbers = [NSUserDefaults standardUserDefaults];
  if ([phoneNumbers objectForKey:@"first"] || [phoneNumbers objectForKey:@"second"]) {
          MFMessageComposeViewController *controller = [[MFMessageComposeViewController alloc] init];
          if ([MFMessageComposeViewController canSendText]) {
              AppDelegate *deleg = (AppDelegate *)[[UIApplication sharedApplication] delegate];
              controller.body = [NSString stringWithFormat:@"some message with coordinates %.4f - %.4f", [deleg currentLocation].coordinate.latitude, [deleg currentLocation].coordinate.longitude];
              controller.recipients = [NSArray arrayWithObjects:[phoneNumbers objectForKey:@"first"], [phoneNumbers objectForKey:@"second"], nil];
              controller.messageComposeDelegate = self;
              [self presentModalViewController:controller animated:YES];
          }
      }
  }
  }
  </code></pre>
  
  <p>Second edit: adding some more code.</p>
  
  <pre><code>UITabBarController *tabBarController = [[UITabBarController alloc] init];
  tabBarController.delegate = self;
  tabBarController.selectedIndex = 0;
  [[tabBarController.tabBar.items objectAtIndex:0] setTitle:NSLocalizedString(@"Home", nil)];
  [[tabBarController.tabBar.items objectAtIndex:1] setTitle:NSLocalizedString(@"Requests", nil)];
  [[tabBarController.tabBar.items objectAtIndex:2] setTitle:NSLocalizedString(@"Account", nil)];
  [[tabBarController.tabBar.items objectAtIndex:3] setTitle:NSLocalizedString(@"Settings", nil)];
  //some other controls from DB
  [[tabBarController.tabBar.items objectAtIndex:1] setBadgeValue:[NSString stringWithFormat:@"%d",number]];
  </code></pre>
  
  <p>The tabbarController has been made via IB, but I've added the code above in my AppDelegate because I need to localize the tab bar items and to add a badge to one of them.
  Am I doing something wrong here?</p>