MFMailComposeViewController's Cancel Button (action sheet possibly) freezes the view

akdsouza picture akdsouza · Dec 13, 2012 · Viewed 7.6k times · Source

I've seen several questions before such as this but for the lack of an accepted answer as well as having implemented everything as needed I still continue to face the issue as follows: I display the mail composer but on clicking cancel, the composer view freezes. I think this is due to the Save/Delete draft action sheet showing up out of the visible frame. Yes I have set the mailComposeDelegate to the presenting view controller and have read up on several similar questions where user's have not handled the (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error delegate to dismiss the composer on cancel. I have handled that as well but I cant seem to figure out for the life of me why the action sheet wont show up in the visible area of the screen in the iPhone version of my universal app. The view frame of the viewcontroller modally presenting the mail composer as NSLogged is (0,0,320,480). My app is universal & the mail composer works perfectly on the iPad. Below is a screenshot of how the composer view looks, running on iPhone Simulator 5.1:-

enter image description here
Here's the code to display the composer:

-(IBAction)mailButtonPressed:(id)sender {

    MFMailComposeViewController *controller = [[MFMailComposeViewController alloc] init];
    controller.mailComposeDelegate = self;
    [controller setSubject:@"Subject"];
    [controller setMessageBody:@"Test" isHTML:YES];
    [controller setToRecipients:nil];

    if(controller) {
        [self presentModalViewController:controller animated:YES];
        [controller release];
    }
}

- (void)mailComposeController:(MFMailComposeViewController*)controller 
          didFinishWithResult:(MFMailComposeResult)result
                        error:(NSError*)error 
{ 
    [self dismissModalViewControllerAnimated:YES];
}

Answer

MacN00b picture MacN00b · Dec 25, 2012

Why not try removing the code, and retrying while following a tutorial online such as this one:

http://iphonedevsdk.com/forum/tutorial-discussion/43633-quick-tutorial-on-how-to-add-mfmailcomposeviewcontroller.html

In cases like these, you always forget the one simple line of code needed to work so following a tutorial helps me make sure all the code necessary is there.

Try this code instead:

- (void) mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error
{
    switch (result)
    {
        case MFMailComposeResultCancelled:
            NSLog(@"Mail cancelled");
            break;
        case MFMailComposeResultSaved:
            NSLog(@"Mail saved");
            break;
        case MFMailComposeResultSent:
            NSLog(@"Mail sent");
            break;
        case MFMailComposeResultFailed:
            NSLog(@"Mail sent failure: %@", [error localizedDescription]);
            break;
        default:
            break;
    }

    // Close the Mail Interface
    [self dismissViewControllerAnimated:YES completion:NULL];
}