3

我有一个 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>

你有什么想法我做错了吗?

第一个模态视图

- (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];    }

在调用 MailView 的 AddListViewController

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];
4

2 回答 2

8

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.

于 2011-09-01T13:23:23.437 回答
3

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

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

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

于 2010-10-21T14:27:45.953 回答