Warning: Attempt to present ViewController on ViewController whose view is not in the window hierarchy

后端 未结 5 929
天命终不由人
天命终不由人 2020-12-29 12:33

I have already looked through related questions but nothing has solved my problem.

I am attempting to use dismissViewControllerAnimated:animated:completion

5条回答
  •  死守一世寂寞
    2020-12-29 13:10

    About this,

    - (IBAction)emailMe:(id)sender {
        [self dismissViewControllerAnimated:YES completion:^{
            [self sendMeMail];
        }];
    }
    

    After dismissing self viewController, you cannot present view controllers from self.

    Then what you can do ?

    1) Change the button press method,

    - (IBAction)emailMe:(id)sender {
        [self sendMeMail];
    }
    

    2) You can dismiss the self viewController, when the mailViewController is dismissed.

    - (void)mailComposeController:(MFMailComposeViewController*)controller
              didFinishWithResult:(MFMailComposeResult)result
                            error:(NSError*)error;
    {
        if (result == MFMailComposeResultSent) {
            NSLog(@"It's sent!");
        }
        [controller dismissViewControllerAnimated:NO completion:^ {
            [self dismissViewControllerAnimated:YES completion:nil];
        }];
    
    }
    

提交回复
热议问题