【发布时间】:2015-07-20 11:57:34
【问题描述】:
在模态创建的视图中,按下按钮会导致模态视图被关闭并加载另一个模态视图。
- (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。
哪里出错了?
【问题讨论】:
-
关闭视图控制器后,它不再在层次结构中,因此出现错误。如果您先获取呈现视图控制器,然后在调用
presentViewController:时将其用作接收器,该怎么办? (不是答案,因为我没有尝试过......但它似乎是合理的。) -
问题是你先解雇了
self,使用[self dismissViewControllerAnimated:YES completion:nil];,然后你试图在self上呈现languageSelectionController。这就是 if 失败的原因。 -
@PhillipMills 有效。谢谢。如果你把你的解决方案写成答案,我会选择它作为正确的。
标签: ios objective-c modal-view