在以模态方式创建的视图中,按下按钮会导致取消模态视图并加载另一个模态视图。
- (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进行一些更改之前,代码运行得很愉快。
哪里出错?
答案 0 :(得分: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];
}];
}