title: 'Application tried to present a nil modal view controller on target' error/crash when trying to open mail composer
body: <p>I have a simple app, which opens a modal view to send email. Am using Xcode 4.2 and iOS 5, and am testing with iOS Simulator. The app crashes with 
       <em>Terminating app due to uncaught exception 'NSInvalidArgumentException', reason:<br>
      'Application tried to present a nil modal view controller on target 
      .'</em></p>
  
  <p>when executing the line:</p>
  
  <pre><code> [self presentModalViewController:mailComposer animated:YES];
  </code></pre>
  
  <p>though I have initialized the object 'mailComposer'.</p>
  
  <p><strong>Class com_FirstViewController.m :</strong></p>
  
  <pre><code>#import "com_FirstViewController.h"
  ...
  @implementation com_FirstViewController
  ....
  ....
  -(void)showEmailComposer {
  
  Class mailClass = (NSClassFromString(@"MFMailComposeViewController"));
  if (mailClass != nil)
  {
      if ([mailClass canSendMail]) {
                      NSLog(@"showEmailComposer: Calling displayComposerSheet");
          [self displayComposerSheet];
  
      } else {
                      NSLog(@"showEmailComposer: Calling launchMailAppOnDevice");
          [self launchMailAppOnDevice];
      }
  }
  else {
              NSLog(@"showEmailComposer: Calling launchMailAppOnDevice");
      [self launchMailAppOnDevice];
  }
  }
  
  
  
  #pragma mark -
  #pragma mark Compose Mail
  
  -(void) displayComposerSheet {
  
      mailComposer = [[MFMessageComposeViewController alloc] init];
      mailComposer.messageComposeDelegate = self;
  
      // Set the mail title
      [mailComposer setTitle:@"Mail Title"];
  
      // Set the recipients
      NSArray *toRecipients = [NSArray arrayWithObject:@"user@company.com"];
  
      [mailComposer setRecipients:toRecipients];
  
      // EMail Body
      NSString *mailBody = @"This is the mail body";
      [mailComposer setBody:mailBody];
  
      NSLog(@"present the modal view ctlr");
      [self presentModalViewController:mailComposer animated:YES];
  }
  ...
  ...
  </code></pre>
  
  <p>Any pointers please?</p>