我有一个简单的应用程序,它打开一个模式视图来发送电子邮件。我正在使用 Xcode 4.2 和 iOS 5,并且正在使用 iOS 模拟器进行测试。由于未捕获的异常“NSInvalidArgumentException”,应用程序崩溃并
终止应用程序,原因:
“应用程序试图在目标上呈现一个 nil 模态视图控制器。”
执行该行时:
[self presentModalViewController:mailComposer animated:YES];
虽然我已经初始化了对象'mailComposer'。
com_FirstViewController.m 类:
#import "com_FirstViewController.h"
...
@implementation com_FirstViewController
....
....
-(void)showEmailComposer {
Class mailClass = (NSClassFromString(@"MFMailComposeViewController"));
if (mailClass != nil)
{
if ([mailClass canSendMail]) {
NSLog(@"showEmailComposer: Calling displayComposerSheet");
[self displayComposerSheet];
} else {
NSLog(@"showEmailComposer: Calling launchMailAppOnDevice");
[self launchMailAppOnDevice];
}
}
else {
NSLog(@"showEmailComposer: Calling launchMailAppOnDevice");
[self launchMailAppOnDevice];
}
}
#pragma mark -
#pragma mark Compose Mail
-(void) displayComposerSheet {
mailComposer = [[MFMessageComposeViewController alloc] init];
mailComposer.messageComposeDelegate = self;
// Set the mail title
[mailComposer setTitle:@"Mail Title"];
// Set the recipients
NSArray *toRecipients = [NSArray arrayWithObject:@"user@company.com"];
[mailComposer setRecipients:toRecipients];
// EMail Body
NSString *mailBody = @"This is the mail body";
[mailComposer setBody:mailBody];
NSLog(@"present the modal view ctlr");
[self presentModalViewController:mailComposer animated:YES];
}
...
...
请问有什么指点吗?