【问题标题】:Warning: Attempted to present * whose not in the window hierarchy警告:试图呈现不在窗口层次结构中的 *
【发布时间】:2014-03-16 01:50:56
【问题描述】:

我已经尝试处理这个问题太久了。请给我你的任何想法。

我通过发送本地通知从 SKScene 呈现视图控制器。 [[NSNotificationCenter defaultCenter] postNotificationName:@"closeScene" object:nil];

通知在开始视图控制器中处理。

- (void)viewDidLoad{ [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(closeScene) name:@"closeScene" object:Nil];
[super viewDidLoad];}

然后:

-(void)closeScene {
//Remove the SKView, or present another viewController here.
constructionViewController *view = [[constructionViewController alloc] init];
[self presentViewController:view animated:YES completion:nil];

[[NSNotificationCenter defaultCenter] removeObserver:self name:@"closeScene" object:nil];

}

每次发送通知时,我都会收到警告:

 Warning: Attempt to present <constructinoViewController: 0x10ae64160> on <constructinoViewController: 0x10ab329d0> whose view is not in the window hierarchy!

任何帮助都将不胜感激。提前谢谢!

【问题讨论】:

    标签: view uiviewcontroller sprite-kit skscene presentviewcontroller


    【解决方案1】:

    closeScene 何时被调用,确切地说 - 之前之后 viewDidAppear 被调用?

    您看到的错误通常发生在您尝试在父级实际显示在屏幕上之前呈现视图控制器时。通常这是因为您在调用父级的 viewDidAppear 方法之前调用了 presentViewController

    尝试将日志语句添加到viewDidAppear 并查看它是否出现在“视图不在窗口层次结构中”错误之前或之后的日志中。如果它在您知道问题所在以及如何解决它之后出现(确保仅在显示父视图控制器后调用presentViewController)。如果是之前你可能有一个完全不同的问题......

    【讨论】:

    • 所以主场景(我们称之为x)是第一个屏幕。从 x 开始,当您按下按钮时,它会呈现场景。场景加载正常,然后当游戏结束时,从场景中调用 closedScene。 closedScene 是 x 中的一种方法。因此,就 viewDidAppear 而言,它应该在应用程序打开开始时被调用,但我不相信它会再次被调用。
    • 如何将初始视图添加到视图层次结构中 - 您的应用有根视图控制器?
    • 你这是什么意思?
    • 您如何在应用启动时创建视图层次结构 - 所有 iOS 应用都应该有一个根视图控制器,我想知道您是否没有一套,这就是导致问题的原因。
    • 我不相信我会这样做...我将如何进行设置一?
    猜你喜欢
    • 1970-01-01
    • 2013-02-23
    • 2017-07-18
    • 2020-08-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-11-19
    • 1970-01-01
    相关资源
    最近更新 更多