title: iOS Mail Composer Won't Dismiss
body: <p>I am trying to take a screenshot and email it using the mail composer.  Everything works great except the mail composer won't dismiss. This post seems to have the same problem, but the solution provided did not work for me. <a href="https://stackoverflow.com/questions/2530283/cannot-dismiss-the-email-composer-view-in-iphone">Can&#39;t dismiss the email composer view in iPhone?</a>  </p>
  
  <pre><code>- (IBAction)Email:(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 setSubject:@"Risk Assessment"];
      [mailComposer addAttachmentData:imageData mimeType:@"image/jpeg" fileName:@"attachment.jpg"];     
      [self presentModalViewController:mailComposer animated:YES];        
  }
  }
  </code></pre>
  
  <p>The above code works great. How do I call this bottom portion.  It seems like the compiler just skips past it.</p>
  
  <pre><code>-(void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error{
  if (error){
      NSString *errorTitle = @"Mail Error";
      NSString *errorDescription = [error localizedDescription];
      UIAlertView *errorView = [[UIAlertView alloc]initWithTitle:errorTitle message:errorDescription delegate:self cancelButtonTitle:nil otherButtonTitles:@"OK", nil];
      [errorView show];                
      [errorView release];
  }
  [controller dismissModalViewControllerAnimated:YES];
  
  }
  </code></pre>
  
  <p>Thanks in advance.</p>