Question

Using MFMailComposeViewController works fine when the phone is in UIInterfaceOrientationPortrait, however If I do not allow autorotation I get something like this when the user rotates the phone:

enter image description here

So I decided to allow the view controller (which is also a modal view), that is a part of the view that calls the modal view to rotate:

RootAppInfoViewController.h

#import <UIKit/UIKit.h>


@interface RootAppInfoViewController : UIViewController <UINavigationControllerDelegate>{
    UINavigationController *navigationControl;
}

@property (nonatomic,retain) IBOutlet UINavigationController *navigationControl;

//dismisses this modal view
- (IBAction)selectHome:(id)sender;

@end

RootAppInfoViewController.m

// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations.
    return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}

(Having this autorotate allows rotation for this entire view by the way). But this is a mere view controller and I want a table view to be presented modally so I have this class, which is referenced through the RootAppInfoViewController.xib which makes this modal view a table view:

AppInfoViewController.h

#import <UIKit/UIKit.h>
#import <MessageUI/MessageUI.h>


@interface AppInfoViewController : UITableViewController <MFMailComposeViewControllerDelegate, UINavigationControllerDelegate> {
    NSMutableArray *dataSourceArray;
}

@property(nonatomic, retain) NSMutableArray *dataSourceArray;

@end

AppInfoViewController.m

//..
/* //NOTE: Commenting or uncommenting this block of code has no effect!
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations.
    return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}//*/
//...
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    NSString *source = [[[self.dataSourceArray objectAtIndex:indexPath.section] objectForKey:kSourceKey] objectAtIndex:indexPath.row];

    if(indexPath.section == kFeedbackSection) {
        if([MFMailComposeViewController canSendMail]) {
            // fill out email
            //...
            MFMailComposeViewController *controller = [[MFMailComposeViewController alloc] init];
            //MailCompose *controller = [[MailCompose alloc] init];
            controller.mailComposeDelegate = self;
            [[controller navigationBar] setTintColor:[UIColor oceanColor]];
            [controller setToRecipients:[NSArray arrayWithObject:kFeedbackEmail]];
            [controller setSubject:emailSubject];
            [controller setMessageBody:emailBodyTemplate isHTML:NO];
            [self presentModalViewController:controller animated:YES];
            [controller release];
        } else {
            [UIAlertHelper mailErrorAlert];
        }
    } //... 

}

#pragma mark -
#pragma mark MFMailComposeViewControllerDelegate methods

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

Commenting or non-commenting out the autorotation code in this class has no effect. holding the device upright and clicking on the row that loads the MFMailComposeViewControlleryeilds no problems, it loads upright, then it rotates just fine. However, loading the table view, holding it sideways and then tapping on the row with the MFMailComposeViewController loads the modal view controller as a blank screen:

enter image description here

This happens both in the simulator and the actual physical device.

Anyone know what's up? Thanks in advance!

Was it helpful?

Solution

In order to adequately explain the answer, I must first elaborate on how my modal view was created.

Here is an overview of my views:

RootViewController -> AppInfoViewController -> MFMailComposeViewController

I had in my RootViewController the following method:

- (IBAction)openEmail:(id)sender {
    AppInfoViewController *aivc = [[AppInfoViewController alloc] initWithNibName:@"AppInfoViewController" bundle:nil];
    aivc.title = @"Email";
    [self presentModalViewController:aivc animated:YES];
    [aivc release];
 }

Which would pop up a modal view controller displaying a table view from which the user will be able to drill down into other views. The problem here is that I created the modal controller without placing the view it first presents into a navigation controller, like so:

- (IBAction)openEmail:(id)sender {
    AppInfoViewController *aivc = [[AppInfoViewController alloc] initWithNibName:@"AppInfoViewController" bundle:nil];
    myNavigationController = [[UINavigationController alloc] initWithRootViewController:aivc];
    aivc.title = @"Email";
    [self presentModalViewController:myNavigationController animated:YES];
    [myNavigationController release];
    [aivc release];
}

After changing my code to the above, everything worked fine. The problem wasn't in AppInfoViewController.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top