title: Warning: Attempt to present UINavigationController on ViewController whose view is not in the window hierarchy
body: <p>I'm working on an ios app and I'm new to it. So, I'm getting this error. What I'm trying to do is when a user first registers on the app, their username is stored locally on the phone using NSUserdefault.</p>
  
  <p>Now if they close the app and reopen it the app goes through the first view controller and in the viewdidload method it checks if the length of the USUserdefault is greater than zero and if yes go to the main activity by perform a segue call. However I get that error when I run it.</p>
  
  <p>This is what I did on my storyboard.
  <img src="https://i.stack.imgur.com/oBS7F.png" alt="enter image description here"></p>
  
  <p>This is the code in the firstviewcontroller</p>
  
  <pre><code>- (void)viewDidLoad
  {
      [super viewDidLoad];
      // Do any additional setup after loading the view, typically from a nib.
      NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults]; NSString *user = [prefs stringForKey:@"userName"];
  
      if(user.length&gt;0){
          NSLog(@"Going straight to main %s", "Yes");
          [self performSegueWithIdentifier:@"startMain" sender:self];
  
      }
  }
  </code></pre>