3
votes

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];}];
}
1
did you do this ? mailer.mailComposeDelegate = self; - Thilina Hewagama
yes i did, i've updated my example code, and the delegating works. In that delegate i do the [self dismissModalViewController...] - jr00n
I'm not sure why your view is black, but you don't need the removeFromParentViewController. Modal views, I'm pretty sure, don't have a parent view controller. - rdelmar
@jr00n, yes you't dont need [self removeFromParentViewController];. just pass nil. - Thilina Hewagama
in your didFinishWithResult method, remove this:-> [self dismissViewControllerAnimated:YES completion:^{[self removeFromParentViewController];}]; try adding this:-> [controller dismissViewControllerAnimated:YES completion:^{[self dismissViewControllerAnimated:YES completion:nil]}]; - Thilina Hewagama

1 Answers

3
votes

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