我创建了一个类来启动 MailComposer,这样我的 iPhone 应用程序在生成各种类型的电子邮件时只有一个地方可以去:一些带有附件,一些没有。有些带有预先填写的地址,有些则没有。
我不希望我的类实现 UIViewController,但它必须这样才能成为 MailComposer 的委托。否则,调用我的类的视图控制器本身必须是 MailComposer 的委托,这违背了目的。
让我的类成为视图控制器的缺点是它必须先加载到屏幕上,然后才能以模态方式调出 MailComposer。不幸的是,视图控制器不能是透明的。效果是,屏幕上的任何内容都会在 MailComposer 出现之前被纯白色视图控制器覆盖片刻。
我也许可以忍受,但不是这样:在 MailComposer 消失后,我的空白视图控制器占据了屏幕。我应该能够通过调用它来从内部摆脱它:
[self.parentViewController dismissModalViewControllerAnimated:NO];
但这死于可怕的死亡:“正在加载 43365 堆栈帧......”
我的班级——一个预先填充然后启动 MailComposer 的 UIViewController——是否丢失了它的 parentViewController?它不是零,因为我已经对此进行了测试。
从当前视图控制器中启动...
// My class is called Email.
Email *oEmail = [[[Email alloc] init] retain];
// Red, to remind myself that I'd like to someday learn to make it transparent.
oEmail.view.backgroundColor = [UIColor redColor];
// Pre-fill whatever fields you want, and specify attachments.
oEmail.EmailSubject = @"I am truly stumped";
// This has to go on screen first.
[self presentModalViewController:oEmail animated:NO];
// Then this can happen, which brings up the MailComposer.
[oEmail f_SendEmail];
// Commenting out the next line didn't help, so I turned it back on.
[oEmail release];
在类内部,您需要 mailComposeController:didFinishWithResult:error: 方法来使 MailComposer 消失,而要实现这一点,该类必须是 MFMailComposeViewControllerDelegate。这是那里发生的事情:
// This gets rid of the mail composer.
[self dismissModalViewControllerAnimated:YES];
// This never fails to get rid of other modal view controllers when called
// from within those controllers, but boy does it not work here.
[self.parentViewController dismissModalViewControllerAnimated:NO];
如果您能帮助我,我将不胜感激!