title: dismiss view controller before presenting another one
body: <p>i am using <strong>MZFormSheetPresentationController</strong> to display a dialogue to ask the user enter his password as shown in the figure bellow:
  <a href="https://i.stack.imgur.com/QCEnx.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/QCEnx.png" alt="dialogue password image"></a> after the user click <strong>OK</strong> another view controller is presented as shown in the figure below:
  <a href="https://i.stack.imgur.com/be5RC.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/be5RC.png" alt="my profile"></a> 
  but after dismissing the new view controller the old view controller still persist i already made some researches about how to dismiss view controller before presenting new one i found one solution <a href="https://stackoverflow.com/questions/23930474/how-to-dismiss-own-view-controller-and-present-another-view-controller-in-a-butt">here</a> using delegate but i am still new to iOS and cannot figure out how to apply such answer in my case here my code what i am using:</p>
  
  <pre><code>- (IBAction)okButtonTouchDown:(id)sender {
  
     // UIStoryboard *storyboard = self.storyboard;
    //  UINavigationController *nav = [storyboard instantiateViewControllerWithIdentifier:@"myprofile"];
     // [self presentViewController:nav animated:YES completion:^{
  
         // [self dismissViewControllerAnimated:YES completion:nil]; // here the self point to the new view controller not to the old one //
  
  
  
  
  //[self dismissViewControllerAnimated:YES completion:^{
  
  
        //  UINavigationController *nav = [storyboard instantiateViewControllerWithIdentifier:@"myprofile"];
       //   [self presentViewController:nav animated:YES completion:^{
  
  
  
          //}];
  
  
      // }];
  
  
     //}];
  
  
  
      __weak EditProfileViewController *aBlockSelf = self;
  UIStoryboard *storyboard = self.storyboard;
  UINavigationController *nav = [storyboard instantiateViewControllerWithIdentifier:@"myprofile"];
   [self   presentViewController:nav animated:YES completion:^{
      [[aBlockSelf presentingViewController] dismissViewControllerAnimated:YES completion:nil];
      }];
  
    }
  
  
  // i try this solution but the new view controller presented and after some time dismissed //
  </code></pre>
  
  <blockquote>
    <p>EVEN if i try to dismissviewcontroller with completion i go into this error  Warning: Attempt to present  on  whose view is not in the window hierarchy!</p>
  </blockquote>
  
  <p>so is there way to solve this problem not using delegate and protocol method ?</p>