2

I'm working on an app and I would like to send, when I press a button, 2 screenshots of 2 views, attached it to an e-mail.

The two view controllers are called secondViewController and commenViewController

Currently I'm using this code:

- (void)buttonPress:(id)sender {
    UIGraphicsBeginImageContext(self.view.frame.size);
    [self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
    UIImage * image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();

    NSData * imageData = UIImageJPEGRepresentation(image, 1.0);

    if ( [MFMailComposeViewController canSendMail] ) {
        MFMailComposeViewController * mailComposer = [[[MFMailComposeViewController alloc] init] autorelease];
        mailComposer.delegate = self;
        [mailComposer addAttachmentData:imageData mimeType:@"image/jpeg" fileName:@"attachment.jpg"];

        /* Configure other settings */

        [self presentModalViewController:mailComposer animated:YES];
    }
}

Which works fine for my first view, but I don't know how to take, in that action, a screenshot of my commenViewController and attach it to the mail as well...

Wain
  • 118,658
  • 15
  • 128
  • 151
Sam VG
  • 143
  • 1
  • 2
  • 9
  • When does an instance of the other view controller exist? Take an image of it at that time and save it? – Wain Jan 04 '14 at 15:24

1 Answers1

0

Wain has the right idea. Before you segue or navigate into your "secondViewController", you should create a screenshot of your "commenViewController" and then save it in a file where you can pick it up in your "secondViewController" "buttonPress" method.

You can create that screenshot before you close or segue or pop the view in the navigation controller to leave "commenViewController".

Michael Dautermann
  • 88,797
  • 17
  • 166
  • 215