ios - 从父屏幕中删除 ViewController 保持黑色

标签 ios objective-c xcode viewcontroller

我在删除模态视图时遇到问题。 我想显示(按下按钮后)我自己的 SendMailViewController,它自己显示 MFMailComposeViewController。然后在按下取消发送后,在我自己的 SendMailView Controller 中的 didFinishWithResult 中,我做了一个 [self dismissModalViewControllerAnimated:YES] 并且有效。 MFMailComposeView 消失了。
但是随后屏幕保持黑色....它认为我还必须从它的父级中删除我的 SendMailViewController。这就是我按下按钮的地方......即使在 [self removeFromParentViewController] 之后它仍然保持黑色......

我哪里出错了?

是的,我想要额外的 View Controller (SendMailViewController),因为该 Controller 将成为 MFMailComposeViewController 的委托(delegate)。否则我的调用者(带按钮的 Controller )将承担很大的责任。还是我这里也出错了?

谢谢,

/jr00n

- (IBAction)tapExportButton:(id)sender
{

    SendMailViewController *sendMailController = [[SendMailViewController alloc]init];

    [self presentViewController:sendMailController animated:YES completion:^()    {[sendMailController openMailDialog];}];

    [sendMailController release];

}

发送邮件 View Controller :

- (void)openMailDialog
{
    if ([MFMailComposeViewController canSendMail])
    {
        MFMailComposeViewController *mailer = [[MFMailComposeViewController alloc] init];
        mailer.mailComposeDelegate = self;
     ...
        [self presentModalViewController:mailer animated:YES];
    }
}


- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
{
....
 // Remove the mail view
 // first i did this:
 // [self dismissModalViewControllerAnimated:YES];

    [self dismissViewControllerAnimated:YES completion:^{[self removeFromParentViewController];}];
}

最佳答案

问题出在 didFinishWithResult 方法中的 [self dismissViewControllerAnimated:YES completion:^{[self removeFromParentViewController];}];
删除该行并添加以下行,

[controller dismissViewControllerAnimated:YES completion:^{[self dismissViewControllerAnimated:YES completion:nil]}];

确保我们在关闭 MailController 之后关闭 Controller

关于ios - 从父屏幕中删除 ViewController 保持黑色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16370694/

相关文章:

objective-c - 如何在 Objective C 中生成二维数组

ios - EXC_BAD_ACCESS 在停止 MPMoviePlayerController 时崩溃

ios - 如何将文件夹中的图像列表上传到我的 xcode 项目中?

ios - 在顶部插入新行后如何使 UITableViewCell 保持在同一位置?

objective-c - 如何在 Apple Watch 上显示警报

java - 在 Xcode 4 中编译 Java

ios - 如何将实例方法作为闭包参数传​​递给另一个函数?

javascript - 从 URL 中获取图像到 objective-c 中的数组中

iphone - 单击引脚注释时如何显示另一个 View

ios - 如何使用 CMake 在 Xcode 中为应用程序扩展创建新目标?