title: Warning: Attempt to present XXX on XXX whose view is not in the window hierarchy
body: <h2>New edit:</h2>
  
  <p>I run into the Warning: </p>
  
  <blockquote>
    <p>Attempt to present OneView on Another whose view is not in the window
    hierarchy.</p>
  </blockquote>
  
  <p>Following is the sample code I created to show the problem.</p>
  
  <p>I have two ViewController: OneViewController and TwoViewController, and subclassed the UIStoryboardSegue class.</p>
  
  <p>The storyboard is like this:
  <img src="https://i.stack.imgur.com/zahuM.png" alt="enter image description here"></p>
  
  <p>Each view contains a button, triggering the segue moving to the other one.</p>
  
  <p>My customer segue's code is like:</p>
  
  <pre><code>- (void)perform {
      UIViewController *sourceVC = self.sourceViewController;
      UIViewController *destinationVC = self.destinationViewController;
  
      [sourceVC.view addSubview:destinationVC.view];
      [destinationVC.view setFrame:sourceVC.view.frame];
      [destinationVC.view setTransform:CGAffineTransformMakeTranslation(320, 0)];
      [destinationVC.view setAlpha:1.0];
  
      [UIView animateWithDuration:0.5
                            delay:0.0
                          options:UIViewAnimationOptionTransitionFlipFromRight
                       animations:^{
                           [destinationVC.view setTransform:CGAffineTransformMakeTranslation(0, 0)];
                           [destinationVC.view setAlpha:1.0];
                       }
                       completion:^(BOOL finished){
                           [destinationVC.view removeFromSuperview];
                           [sourceVC presentViewController:destinationVC animated:NO completion:nil];
                       }];
  }
  </code></pre>
  
  <p>i.e., I want to move the destinationView from right to center.</p>
  
  <p>In the TwoViewController, I also have a UITextField.</p>
  
  <p>The whole code in two viewcontroller is like:</p>
  
  <p>OneViewController:</p>
  
  <pre><code>#import "OneViewController.h"
  
  @interface OneViewController ()
  
  @end
  
  @implementation OneViewController
  
  - (void)viewDidLoad
  {
      [super viewDidLoad];
      // Do any additional setup after loading the view.
  }
  
  - (void)didReceiveMemoryWarning
  {
      [super didReceiveMemoryWarning];
      // Dispose of any resources that can be recreated.
  }
  
  - (IBAction)btnTapped:(id)sender {
      [self performSegueWithIdentifier:@"One2TwoSegue" sender:self];
  }
  
  @end
  </code></pre>
  
  <p>TwoViewController:</p>
  
  <pre><code>#import "TwoViewController.h"
  
  @interface TwoViewController ()
  
  - (void)keyboardDidHide:(NSNotification*)notification;
  
  @end
  
  @implementation TwoViewController
  
  - (void)viewDidLoad
  {
      [super viewDidLoad];
  
      [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardDidHide:) name:UIKeyboardDidHideNotification object:nil];
  }
  
  - (void)didReceiveMemoryWarning
  {
      [super didReceiveMemoryWarning];
      // Dispose of any resources that can be recreated.
  }
  
  - (IBAction)btnTapped:(id)sender {
      [_inputBox resignFirstResponder];
  }
  
  - (void)keyboardDidHide:(NSNotification *)notification {
      [self performSegueWithIdentifier:@"Two2OneSegue" sender:self];
  }
  
  @end
  </code></pre>
  
  <p>In the TwoViewController, the reason I wrote like this is because I want to hide the keyboard before performing the segue.</p>
  
  <p>Now, If I do this:</p>
  
  <p>start the app => tap "Change to Two" => tap the textfield to show the keyboard => tap "Change to One"(then the keyboard will hiding, after that, the view will change) => tap "Change to Tow" => tap the textfield to show the keyboard => tap "Change to One"</p>
  
  <p>Then, I got the warning:</p>
  
  <blockquote>
    <p>Warning: Attempt to present  on
     whose view is not in the window
    hierarchy!</p>
  </blockquote>
  
  <p>And, if I repeat once more, I will get 2 warnings...Once more again, I will get 3...and so on..</p>
  
  <p>In addition, if I remove the textfield, just two buttons, everything is fine.</p>
  
  <p>Could anyone help???</p>