开发者

MFMailComposeViewController Blank Screen When Opening in Landscape Mode

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:

MFMailComposeViewController Blank Screen When Opening in Landscape Mode

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];
        }
    } //... 

}
开发者_Python百科
#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:

MFMailComposeViewController Blank Screen When Opening in Landscape Mode

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

Anyone know what's up? Thanks in advance!


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜