微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

在横向模式下打开时,MFMailComposeViewController黑屏

如何解决在横向模式下打开时,MFMailComposeViewController黑屏

| 当手机处于UIInterfaceOrientationPortrait时,使用MFMailComposeViewController可以正常工作,但是,如果我不允许自动旋转,则当用户旋转手机时会得到类似以下的信息: 因此,我决定允许视图控制器(也是模态视图),这是调用模态视图的视图的一部分旋转: 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);
}
(顺便说一下,具有此自动旋转功能可旋转整个视图)。但这只是一个视图控制器,我希望以模态形式呈现表视图,因此我拥有此类,该类通过RootAppInfoViewController.xib进行引用,该类使该模式视图成为表视图: 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];
}
注释或不注释此类中的自动旋转代码无效。保持设备竖直,然后单击加载MFMailComposeViewControlleryy的行,没有问题,将其竖直放置,然后旋转即可。但是,加载表格视图,将其保持在侧面,然后使用MFMailComposeViewController点击该行,将模式视图控制器加载为空白屏幕: 这在模拟器和实际物理设备中均会发生。 有人知道怎么回事吗?提前致谢!     

解决方法

为了充分解释答案,我必须首先详细说明我的模态视图是如何创建的。 这是我的观点的概述:
RootViewController -> AppInfoViewController -> MFMailComposeViewController
我在RootViewController中具有以下方法:
- (IBAction)openEmail:(id)sender {
    AppInfoViewController *aivc = [[AppInfoViewController alloc] initWithNibName:@\"AppInfoViewController\" bundle:nil];
    aivc.title = @\"Email\";
    [self presentModalViewController:aivc animated:YES];
    [aivc release];
 }
它将弹出一个模态视图控制器,显示一个表视图,用户可以从中向下钻取其他视图。这里的问题是我创建了模态控制器,而没有将它首先出现的视图放置到导航控制器中,如下所示:
- (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];
}
将我的代码更改为以上代码后,一切正常。问题不在AppInfoViewController中。     

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。