MFMailComposeViewController 以横向模式打开时出现黑屏

发布于 2024-11-09 16:53:47 字数 3631 浏览 0 评论 0原文

当手机处于 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];
}

注释或非注释注释掉此类中的自动旋转代码没有任何效果。保持设备直立并单击加载 MFMailComposeViewController 的行不会有任何问题,它会直立加载,然后旋转得很好。但是,加载表格视图,将其侧向放置,然后使用 MFMailComposeViewController 点击该行,会将模式视图控制器加载为空白屏幕:

“在此处输入图像描述”

这种情况在模拟器和实际物理设备中都会发生。

有人知道怎么回事吗?提前致谢!

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

烟─花易冷 2024-11-16 16:53:47

为了充分解释答案,我必须首先详细说明我的模态视图是如何创建的。

以下是我的观点概述:

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 中。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文