作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我使用 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];
}
* Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Application tried to present a nil modal view controller on target .'* First throw call stack:()libc++abi.dylib: terminating with uncaught exception of type NSException
最佳答案
NSInvalidArgumentException', reason: 'Application tried to present a nil modal view controller on target -- It means you try to implement the nil objcet on target check once if it is nil or not
MFMailComposeViewController *mc = [[MFMailComposeViewController alloc] init];
if (!mc) {
//When the device has not added mailViewController mail account is empty , the following present view controller causes the program to crash here
NSLog(@"no email accounts are set up in your device");
return;
}
关于ios - NSInvalidArgumentException',原因 : 'Application tried to present a nil modal view controller on target,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35555770/
我是一名优秀的程序员,十分优秀!