当手机处于 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 在行上点击,将模式视图控制器加载为空白屏幕:
这发生在模拟器和实际的物理设备中。
有谁知道怎么回事?提前致谢!