简体   繁体   中英

Presenting MFMailComposeViewController, but it disappears right after it's visible

The first ViewController in my app subclasses UIImagePickerController and then through the didFinishPickingMediaWithInfo callback, I do the following:

EditViewController *editViewController = [[EditViewController alloc] initWithNibName:@"EditViewController" bundle:nil];
[self pushViewController:editViewController animated:YES];

this ViewController displays properly... Then, through an IBAction, I do the following:

PreviewViewController *previewViewController = [[PreviewViewController alloc] initWithNibName:@"PreviewViewController" bundle:nil];
previewViewController.tempImage = img;
[self.navigationController pushViewController:previewViewController animated:YES];

This view also displays correctly. In this VC I'm trying to use the MFMailComposeViewController for sending an email. When I attempt to push it, I get Pushing a navigation controller is not supported :

MFMailComposeViewController *mailViewController = [[MFMailComposeViewController alloc] init];
mailViewController.mailComposeDelegate = self;
[mailViewController setSubject:@"Subject Goes Here."];
[mailViewController setMessageBody:@"Your message goes here." isHTML:NO];
[self.navigationController pushViewController:mailViewController animated:YES];

But when I present it instead:

[self presentModalViewController:mailViewController animated:YES];

The mailViewController appears for only a second and then disappears and I see a black background (but not the previous VC's view) with an empty navbar on top. The app is still running at this point.

What am I doing wrong?

If you still want to push the mailViewController you can do this (iOS 7 only):

UIViewController *theMailViewController = [[mailViewController viewControllers] lastObject];
[self.navigationController pushViewController:theMailViewController animated:YES];

That way the MailViewController's rootViewController will get pushed into your actual navigationController.

I hope this helps you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM