使用MFMailComposeViewController在手机处于UIInterfaceOrientationPortrait时工作正常,但是如果我不允许自动旋转,当用户旋转手机时,我会得到类似的内容:
所以我决定允许视图控制器(也是一个模态视图),它是调用模态视图旋转的视图的一部分:
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];
}
在此课程中评论或不评论自动旋转代码无效。直接按住设备并单击加载MFMailComposeViewControlleryeilds的行没有任何问题,它会直立加载,然后旋转就好了。但是,加载表视图,将其保持在侧面然后使用MFMailComposeViewController点击该行会将模态视图控制器加载为空白屏幕:
在模拟器和实际物理设备中都会发生这种情况。
任何人都知道怎么了?提前谢谢!
答案 0 :(得分:0)
为了充分解释答案,我必须先详细说明我的模态视图是如何创建的。
以下是我的观点概述:
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。