-1

I'm using the standard setup procedure for Mobclix in an iOS app and I'm calling the requestAndDisplayAdFromViewController: method from within viewWillAppear:

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

    [fullScreenAdViewController requestAndDisplayAdFromViewController:self];

}

here's the warning I'm getting:

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

I hope that's enough to go on. thanks for any help.

Arun
  • 3,406
  • 4
  • 30
  • 55
hanumanDev
  • 6,592
  • 11
  • 82
  • 146

4 Answers4

3

You're calling it from viewWillAppear - at this point, the view is not necessarily in the hierarchy yet (it WILL appear, doesn't mean it has appeared yet). Try calling it from viewDidAppear, which is called when the view is confirmed to be in the hierarchy.

Jai Govindani
  • 3,181
  • 21
  • 26
0

Try to move your code [fullScreenAdViewController requestAndDisplayAdFromViewController:self]; to viewDidAppear.

nsgulliver
  • 12,655
  • 23
  • 43
  • 64
0

You can also try to display the view in the viewDidLoad method.

Fabrizio Duroni
  • 747
  • 1
  • 11
  • 24
0

You should try moving this code to viewDidAppear.

From the Apple documentation on viewWillAppear:

This method is called before the receiver’s view is about to be added to a view hierarchy
Kaiser
  • 688
  • 4
  • 12
  • even after moving it to didAppear I still get the Warning: Attempt to present on whose view is not in the window hierarchy! – hanumanDev Mar 27 '13 at 13:26
  • 1
    I would iterate over the view controllers in the stack to get a clearer picture of what's going on. Get a pointer to your root view controller, and then iterate over the `viewControllers` array (if it's a UINavigationController) and see what exactly is in the hierarchy. – Jai Govindani Mar 27 '13 at 14:11