How to fix the warning: view is not in the window hierarchy

1.2k views Asked by At

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.

4

There are 4 answers

0
Jai Govindani On

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.

0
nsgulliver On

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

0
Fabrizio Duroni On

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

2
Kaiser On

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