Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 700395
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T03:29:34+00:00 2026-05-14T03:29:34+00:00

I created a class to launch the MailComposer so that my iPhone app would

  • 0

I created a class to launch the MailComposer so that my iPhone app would only have one place to go when generating various kinds of e-mail: some with attachments, some not. Some with pre-filled addresses, some not.

I didn’t want my class implement UIViewController, but it has to so it can be the delegate for the MailComposer. Otherwise, the view controllers that call my class would themselves have to be delegates for the MailComposer, which defeats the purpose.

The downside of having my class be a view controller is that it has to load to the screen before it can modally bring up the MailComposer. Unfortunately, view controllers can’t be transparent. The effect is, whatever is on screen gets covered by a solid white view controller for a moment before the MailComposer appears.

I could maybe live with that, but not this: after the MailComposer goes away, I’m left with my blank view controller occupying the screen. I ought to be able to get rid of it from within itself by calling this:

[self.parentViewController dismissModalViewControllerAnimated:NO];

But that dies a horrible death: “Loading 43365 stack frames…”

Has my class — a UIViewController that pre-fills and then launches a MailComposer — lost track of its parentViewController? It isn’t nil, because I’ve tested for that.

As launched from within the current view controller…

// My class is called Email.
Email *oEmail = [[[Email alloc] init] retain];
// Red, to remind myself that I'd like to someday learn to make it transparent.
oEmail.view.backgroundColor = [UIColor redColor]; 
// Pre-fill whatever fields you want, and specify attachments.
oEmail.EmailSubject = @"I am truly stumped";
// This has to go on screen first.
[self presentModalViewController:oEmail animated:NO];
// Then this can happen, which brings up the MailComposer.
[oEmail f_SendEmail];
// Commenting out the next line didn't help, so I turned it back on.
[oEmail release];

Inside the class, you need the mailComposeController:didFinishWithResult:error: method to make the MailComposer go away, and for that to happen, the class has to be the MFMailComposeViewControllerDelegate. Here’s what happens in there:

// This gets rid of the mail composer.
[self dismissModalViewControllerAnimated:YES];

// This never fails to get rid of other modal view controllers when called
// from within those controllers, but boy does it not work here.
[self.parentViewController dismissModalViewControllerAnimated:NO];

If you can help me, I will be truly thankful!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T03:29:34+00:00Added an answer on May 14, 2026 at 3:29 am

    Instead of calling

    [self.parentViewController dismissModalViewControllerAnimated:NO];
    

    I would set up a delegate for your ‘Email’ controller.
    An example of this sort of connection can be seen in the ‘FlipSide’ application template when creating a new project.

    Basically, you would set up a delegate for the Email controller:

    Email *oEmail = [[[Email alloc] init] retain];
    oEmail.view.backgroundColor = [UIColor redColor]; 
    oEmail.EmailSubject = @"I am truly stumped";
    [self presentModalViewController:oEmail animated:NO];
    [oEmail f_SendEmail];
    [oEmail setDelegate:self];
    [oEmail release];
    

    Then in the Email .h file:

    @protocol EmailDelegate
    -(void)emailDidFinish;
    @end
    
    @implementation Email : UIViewController {
          // Other stuff
          id <EmailDelegate> delegate;
    }
    
    @property (nonatomic, assign) id <EmailDelegate> delegate;
    
    @end
    

    Make sure you @synthesize delegate, then when you’re ready to dismiss it call:

    // This gets rid of the mail composer.
    [self dismissModalViewControllerAnimated:YES];
    
    // This never fails to get rid of other modal view controllers when called
    // from within those controllers, but boy does it not work here.
    if (delegate && [delegate respondsToSelector:@selector(emailDidFinish)]){
       [delegate emailDidFinish];
    }
    

    And finally, in your original view controller, make sure you’ve got in the .h file and then have:

    -(void)emailDidFinish {
       [self dismissModal...];
    }
    

    Hope that helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have several USB mass storage flash drives connected to a Ubuntu Linux computer
I have a snippet to create a 'Like' button for our news site: <iframe
I notice in several API's, that you may create a struct which is used
After having read Ian Boyd 's constructor series questions ( 1 , 2 ,
I am attempting to pull some information from my tnsnames file using regex. I
I need to solve the following question which i can't get to work by
I'm trying to build a C++ extension for python using swig. I've followed the
There doesn't seem to be any tried and true set of best practices to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.