presentModalViewController使我的应用程

presentModalViewController使我的应用程

本文介绍了presentModalViewController使我的应用程序崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我要做的最简单的事情之一.但是好几天以来,我一直在努力应对.过去,我已经做过很多次了,但是由于某种原因,试图呈现一个模态视图控制器只会使应用程序崩溃到黑屏.控制台中未报告任何内容.我希望有人可能遇到此问题并提供一些建议.

It's one of the simplest things to do, I know. But I've been banging my head against this for days. I've done it plenty of times in the past, but for some reason trying to present a modal view controller just crashes the app to a black screen. Nothing reported in the console or anything. I'm hoping someone might have had this problem and has some advice.

此代码是从UIViewController类调用的:

This code is called from a UIViewController class:

MFMailComposeViewController *controller = [[MFMailComposeViewController alloc] init];
controller.mailComposeDelegate = self;
[controller setSubject:@"test subject"];
[controller setMessageBody:@"this is the message body" isHTML:NO];
[self presentModalViewController:controller animated:YES];

推荐答案

在尝试显示MFMailComposeViewController之前,您是否正在显示另一个模式视图控制器?我遇到了同样的问题,找到了解决方法:

Are you showing another modal view controller before trying to show MFMailComposeViewController? I had the same problem and found a workaround:

- (void)peopleMultiPickerNavigationController:(PeopleMultiPickerNavigationController *)peoplePicker
                                didSelectContacts:(NSArray *)contacts {

[self dismissModalViewControllerAnimated:YES];

// some more code here

[self performSelector:@selector(sendEmail) withObject:nil afterDelay:0.45]; // this works only if delay > ~0.4!
// [self sendEmail]; // this won't work

// some more code here

}

- (void) sendEmail {
  Class mailClass = (NSClassFromString(@"MFMailComposeViewController"));
  if (mailClass != nil) {
    // We must always check whether the current device is configured for sending emails
    if ([mailClass canSendMail]) {
      [self displayComposerSheet:emails];
    } else {
      [self launchMailAppOnDevice:emails];
    }
  } else {
    [self launchMailAppOnDevice:emails];
  }
}

我知道这是一个丑陋的解决方法,但是我没有发现更好的方法:(

I know it's an ugly workaround, but I didn't found anything better :(

这篇关于presentModalViewController使我的应用程序崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-24 20:56