【发布时间】:2016-06-04 00:07:15
【问题描述】:
我使用 Xcode 7.3 beta 3 创建了一封电子邮件。我从 appcoda 获取代码
- (IBAction)showEmail:(id)sender {
// Email Subject
NSString *emailTitle = @"Test Email";
// Email Content
NSString *messageBody = @"iOS programming is so fun!";
// To address
NSArray *toRecipents = [NSArray arrayWithObject:@"support@appcoda.com"];
MFMailComposeViewController *mc = [[MFMailComposeViewController alloc] init];
mc.mailComposeDelegate = self;
[mc setSubject:emailTitle];
[mc setMessageBody:messageBody isHTML:NO];
[mc setToRecipients:toRecipents];
// Present mail view controller on screen
[self presentViewController:mc animated:YES completion:NULL];
}
- (void) mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error
{
switch (result)
{
case MFMailComposeResultCancelled:
NSLog(@"Mail cancelled");
break;
case MFMailComposeResultSaved:
NSLog(@"Mail saved");
break;
case MFMailComposeResultSent:
NSLog(@"Mail sent");
break;
case MFMailComposeResultFailed:
NSLog(@"Mail sent failure: %@", [error localizedDescription]);
break;
default:
break;
}
// Close the Mail Interface
[self dismissViewControllerAnimated:YES completion:NULL];
}
但在 iPhone 上运行应用程序后,它给了我一个错误(如下所示)
* 由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“应用程序试图在目标上呈现 nil 模态视图控制器。”* 首先抛出调用堆栈:()libc++abi。 dylib:以 NSException 类型的未捕获异常终止
【问题讨论】:
-
当您收到此错误时,例如,如果您按下
showEmail:(id)sender这个或其他地方的按钮 -
我不太明白,你能解释一下吗?
-
当你收到错误
Application tried to present a nil modal view controller on target
标签: ios objective-c iphone xcode