Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

remove ViewController from parent screen stays black

I'm having trouble with removing a modal view. I want to show (after pressing a button) a my own SendMailViewController which it self shows a MFMailComposeViewController. Then and after pressing cancel of send, in my own SendMailView controller in didFinishWithResult i do a [self dismissModalViewControllerAnimated:YES] and that works. The MFMailComposeView goes away.
But then the screen stays black....it think i also have to remove my SendMailViewController from it's parent. That's where i pushed the button...even after [self removeFromParentViewController] it still stays black...

Where do i go wrong?

And yes i would like the extra viewcontroller (SendMailViewController) because that controller will become the delegate of MFMailComposeViewController. Otherwise my caller (controller with the button) get's to much responsibility. Or do i also go wrong here?

Thanks,

/jr00n

- (IBAction)tapExportButton:(id)sender
{

    SendMailViewController *sendMailController = [[SendMailViewController alloc]init];

    [self presentViewController:sendMailController animated:YES completion:^()    {[sendMailController openMailDialog];}];

    [sendMailController release];

}

SendMailViewController:

- (void)openMailDialog
{
    if ([MFMailComposeViewController canSendMail])
    {
        MFMailComposeViewController *mailer = [[MFMailComposeViewController alloc] init];
        mailer.mailComposeDelegate = self;
     ...
        [self presentModalViewController:mailer animated:YES];
    }
}


- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
{
....
 // Remove the mail view
 // first i did this:
 // [self dismissModalViewControllerAnimated:YES];

    [self dismissViewControllerAnimated:YES completion:^{[self removeFromParentViewController];}];
}
like image 886
jr00n Avatar asked Sep 01 '26 16:09

jr00n


1 Answers

The problem is with the [self dismissViewControllerAnimated:YES completion:^{[self removeFromParentViewController];}]; in your didFinishWithResult method.
Remove that line and add the following line,

[controller dismissViewControllerAnimated:YES completion:^{[self dismissViewControllerAnimated:YES completion:nil]}];

That make sure we dismiss the controller after dismissing the MailController

like image 92
Thilina Chamath Hewagama Avatar answered Sep 03 '26 11:09

Thilina Chamath Hewagama



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!