0

在模态创建的视图中,按下按钮会导致模态视图被关闭并加载另一个模态视图。

- (void)loadLanguageSelectionView {
    [self dismissViewControllerAnimated:YES completion:nil];
    UIViewController *languageSelectionController = [[LanguageSelectionViewController alloc] initWithNibName:nil bundle:nil];
    [languageSelectionController setModalPresentationStyle:UIModalPresentationCustom];
    [languageSelectionController setModalTransitionStyle:UIModalTransitionStyleCrossDissolve];
    [self presentViewController:languageSelectionController animated:YES completion:nil];
}

执行此代码块时会引发以下错误:

DenkoStation[4259:73173] Warning: Attempt to present <LanguageSelectionViewController: 0x7b185430> on <ViewController: 0x79f52e50> whose view is not in the window hierarchy!

令我吃惊的是,在我按照此处所述对代码进行一些更改之前,代码运行良好。

哪里错了?

4

1 回答 1

1

因为您正试图在已关闭且不再位于窗口层次结构中的 viewController 之上呈现 viewController。

您可以尝试的是,您可以从当前 viewController 获取 ParentViewController 引用,然后您可以在 ParentViewController 上呈现新的 viewController,如下所示:

- (void)loadLanguageSelectionView {
    UIViewController *parentController = self.presentingViewController;
    [self dismissViewControllerAnimated:YES completion:^{
        UIViewController *languageSelectionController = [[LanguageSelectionViewController alloc] initWithNibName:nil bundle:nil];
        [languageSelectionController setModalPresentationStyle:UIModalPresentationCustom];
        [languageSelectionController setModalTransitionStyle:UIModalTransitionStyleCrossDissolve];
        [parentController presentViewController:languageSelectionController animated:YES completion:nil];
    }];
}
于 2015-07-20T12:09:07.760 回答