我知道,这是最简单的事情之一.但是我这几天一直在反对这个.过去我已经做过很多次了,但由于某种原因,试图呈现模态视图控制器只会使应用程序崩溃到黑屏.控制台中没有任何报告或任何内容.我希望有人可能遇到过这个问题并提供一些建议.
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 使我的应用程序崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!