gpt4 book ai didi

ios - NSInvalidArgumentException',原因 : 'Application tried to present a nil modal view controller on target

转载 作者:行者123 更新时间:2023-12-01 18:08:58 24 4
gpt4 key购买 nike

我使用 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 上运行应用程序后,它给了我一个错误(如下所示)

* 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;
}

sample tutorial

关于ios - NSInvalidArgumentException',原因 : 'Application tried to present a nil modal view controller on target,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35555770/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com