【问题标题】:How to fix the warning: view is not in the window hierarchy如何修复警告:视图不在窗口层次结构中
【发布时间】:2013-03-27 13:04:12
【问题描述】:

我在iOS 应用程序中使用Mobclix 的标准设置过程,并从viewWillAppear: 中调用requestAndDisplayAdFromViewController: 方法

    - (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];

    [fullScreenAdViewController requestAndDisplayAdFromViewController:self];

}

这是我收到的警告:

Warning: Attempt to present <MobclixFullScreenAdViewController: 0x14f2c0> on <EditGameViewController: 0x1838d0> whose view is not in the window hierarchy!

我希望这已经足够了。感谢您的帮助。

【问题讨论】:

    标签: iphone ios objective-c mobclix


    【解决方案1】:

    您从 viewWillAppear 调用它 - 此时,视图不一定在层次结构中(它会出现,并不意味着它已经出现)。尝试从 viewDidAppear 中调用它,当视图被确认在层次结构中时调用它。

    【讨论】:

      【解决方案2】:

      尝试将您的代码[fullScreenAdViewController requestAndDisplayAdFromViewController:self]; 移动到viewDidAppear。

      【讨论】:

        【解决方案3】:

        您也可以尝试在 viewDidLoad 方法中显示视图。

        【讨论】:

          【解决方案4】:

          您应该尝试将此代码移至 viewDidAppear。

          来自关于 viewWillAppear 的 Apple 文档:

          This method is called before the receiver’s view is about to be added to a view hierarchy
          

          【讨论】:

          • 即使在将其移至 didAppear 之后,我仍然收到警告:尝试在 上呈现 其视图不在窗口层次结构中!
          • 我会遍历堆栈中的视图控制器以更清楚地了解正在发生的事情。获取指向根视图控制器的指针,然后遍历 viewControllers 数组(如果它是 UINavigationController)并查看层次结构中的确切内容。
          猜你喜欢
          • 1970-01-01
          • 2018-06-27
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2015-03-25
          • 2013-02-23
          • 2020-08-07
          • 2017-07-18
          相关资源
          最近更新 更多