两个ModalViewController

发布于 2024-09-28 14:57:57 字数 2155 浏览 6 评论 0原文

我有一个 navigationController,从中启动 ModalViewController。 在此 ModalViewController 中,我将显示 MailComposer,它本身是另一个 ModalViewController。

现在,如果用户点击发送按钮,MailComposerView 以及其他 ModalViewController 都应该被关闭。为此,我在 mailComposerController 中调用委托方法。

现在只有 MailComposerView 将被解雇,但其他 ModalViewController 不会被解雇,我收到以下错误消息

attempt to dismiss modal view controller whose view does not currently appear. self = <UINavigationController: 0x724d500> modalViewController = <UINavigationController: 0x72701f0>

您知道我做错了吗?

第一个 ModalView

- (void)addList {
NSLog(@"addList");

//AddListViewController *addListViewController = [[AddListViewController alloc] init];
AddListViewController *addListViewController = [[AddListViewController alloc] initWithStyle:UITableViewStyleGrouped];
addListViewController.delegate = self;

UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:addListViewController];
navigationController.navigationBar.barStyle = UIBarStyleBlack;
navigationController.navigationBar.translucent = YES;
[self presentModalViewController:navigationController animated:YES];

[navigationController release];
[addListViewController release];    }

在 AddListViewController 中调用 MailView

MFMailComposeViewController *mailComposer = [[MFMailComposeViewController alloc] init];
    mailComposer.mailComposeDelegate = self;

    NSString *subject = [NSString stringWithFormat:@"Group invite for groupname: %@", @"mhm"];
    [mailComposer setSubject:subject];

    // Fill out the email body text
    NSString *emailBody = @"This is an group invite bla bla";
    [mailComposer setMessageBody:emailBody isHTML:NO];

    [self presentModalViewController:mailComposer animated:YES];
    [mailComposer release]; 

在 mailComposerController 方法中

[self.navigationController dismissModalViewControllerAnimated:YES];
[self.delegate finishAddList:checkmark andListName:listName.text];

在 finsihAddList 委托中

[self dismissModalViewControllerAnimated:YES];

I have a navigationController from where I launch a ModalViewController.
In this ModalViewController I will display the MailComposer which itself another ModalViewController.

Now if the user hits the send button the MailComposerView should be dismissed as well the other ModalViewController. For that I call a delegate method in the mailComposerController.

Now only the MailComposerView will be dismissed but no the the other ModalViewController and I get following error message

attempt to dismiss modal view controller whose view does not currently appear. self = <UINavigationController: 0x724d500> modalViewController = <UINavigationController: 0x72701f0>

Do you have any Idea would I'm doing wrong?

First ModalView

- (void)addList {
NSLog(@"addList");

//AddListViewController *addListViewController = [[AddListViewController alloc] init];
AddListViewController *addListViewController = [[AddListViewController alloc] initWithStyle:UITableViewStyleGrouped];
addListViewController.delegate = self;

UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:addListViewController];
navigationController.navigationBar.barStyle = UIBarStyleBlack;
navigationController.navigationBar.translucent = YES;
[self presentModalViewController:navigationController animated:YES];

[navigationController release];
[addListViewController release];    }

In the AddListViewController calling the MailView

MFMailComposeViewController *mailComposer = [[MFMailComposeViewController alloc] init];
    mailComposer.mailComposeDelegate = self;

    NSString *subject = [NSString stringWithFormat:@"Group invite for groupname: %@", @"mhm"];
    [mailComposer setSubject:subject];

    // Fill out the email body text
    NSString *emailBody = @"This is an group invite bla bla";
    [mailComposer setMessageBody:emailBody isHTML:NO];

    [self presentModalViewController:mailComposer animated:YES];
    [mailComposer release]; 

In the mailComposerController method

[self.navigationController dismissModalViewControllerAnimated:YES];
[self.delegate finishAddList:checkmark andListName:listName.text];

In the finsihAddList delegate

[self dismissModalViewControllerAnimated:YES];

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

假装不在乎 2024-10-05 14:57:57

我有类似的问题。我有一堆模态呈现的视图控制器。当我尝试从可见的开始并向下移动堆栈时,我会因同样的错误而失败。解决方案是关闭堆栈底部的视图控制器。它会忽略它之上的所有内容。

在您的情况下,我的解决方案相当于更改 mailComposerController 方法,使其仅包含一行(不会忽略最顶层的模态 vie 控制器)。

[self.delegate finishAddList:checkmark andListName:listName.text];

我知道您已经解决了问题,但我认为这可能对其他人有帮助。

I had a similar problem. I had a stack of modally presented view controllers. When I tried to dismiss them starting with the visible one, and moving down the stack, I would fail with the same error. The solution was to dismiss the view controller at the bottom of the stack. It would dismiss everything above it.

In your case, my solution would amount to changing the mailComposerController method so that it contains only one line (does not dismiss the top-most modal vie controller).

[self.delegate finishAddList:checkmark andListName:listName.text];

I know you've resolved your problem already, but thought this might be helpful for others.

尐偏执 2024-10-05 14:57:57

您必须延迟调用第二次解雇,因为调用时第一次解雇尚未完成。

[self performSelector: @selector(finish:) withObject: obj afterDelay: 0.0f];

0.0f 的延迟是有意的,这意味着它将在下一个事件循环中完成。

You must call the second dismiss with a delay, because the first dismiss hasn't been done yet when called.

[self performSelector: @selector(finish:) withObject: obj afterDelay: 0.0f];

A delay of 0.0f is intentional, it means it will be done in the next event loop.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文