gpt4 book ai didi

ios - 从另一个模态视图创建模态视图失败

转载 作者:行者123 更新时间:2023-11-29 01:49:59 24 4
gpt4 key购买 nike

在以模态方式创建的 View 中,按下按钮会导致模态视图消失并加载另一个模态视图。

- (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!

令我惊讶的是,在我对代码进行一些更改之前,代码运行得很愉快 as outlined here .

错在哪里?

最佳答案

因为您正试图在已关闭且不再位于窗口层次结构中的 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];
}];
}

关于ios - 从另一个模态视图创建模态视图失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31515910/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com