-1

I have a iPad app with 2 view controllers; 1st one is for the UI, the 2nd for a view which displays help from a UIWebView. When I go back and forth 10 times between view controllers, I get the message in the title above on exactly the 10th time returning to the first VC.

This is my code in VC #1:

- (void)viewDidAppear:(BOOL)animated  {

[super viewDidAppear:animated];

adView = [[ADBannerView alloc] initWithFrame:CGRectMake(0, self.view.frame.size.height - 50, 320, 50)];

_adBanner = [[ADBannerView alloc] initWithFrame:CGRectMake(0, self.view.frame.size.height, 320, 50)];
_adBanner.delegate = self;

[self.view addSubview:adView];
}


- (void) viewWillDisappear:(BOOL)animated  {

[_adBanner removeFromSuperview];
_adBanner.delegate = nil;
_adBanner = nil;

}


- (void)bannerViewDidLoadAd:(ADBannerView *)banner  {

if (!_bannerIsVisible)  {

    // If banner isn't part of view hierarchy, add it
    if (_adBanner.superview == nil)
        [self.view addSubview:_adBanner];
    //        }

    [UIView beginAnimations:@"animateAdBannerOn" context:NULL];

    // Assumes the banner view is just off the bottom of the screen.
    banner.frame = CGRectOffset(banner.frame, 0, -banner.frame.size.height);

    [UIView commitAnimations];

    _bannerIsVisible = YES;
    }
}


- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error  {

NSLog(@"Failed to retrieve ad");

if (_bannerIsVisible)  {

    [UIView beginAnimations:@"animateAdBannerOff" context:NULL];

    // Assumes the banner view is placed at the bottom of the screen.
    banner.frame = CGRectOffset(banner.frame, 0, banner.frame.size.height);

    [UIView commitAnimations];

    _bannerIsVisible = NO;
    }
}

I know why, just don't know how to fix it. Can someone please help me with this?

SpokaneDude
  • 4,856
  • 13
  • 64
  • 120
  • what is `adView` and why do you create it then appear to do nothing with it ever again. also you should be calling `[super viewWillDisappear:]` – Warren Burton Feb 25 '15 at 19:19
  • Please re-write your comment as an Answer -- I removed *adView* and made *_adBanner* the subView... works like a charm now! Thank you for your time, I appreciate it! SD – SpokaneDude Feb 25 '15 at 19:36

1 Answers1

0

You create an instance of ADBannerView in viewDidAppear and assign it to adView You don't appear do anything with this and more relevantly don't discard it in viewWillDisappear so each time you pop back to this view controller the previous instance is orphaned when you cycle through viewDidAppear.

Also possibly another issue is that you are not calling [super viewWillDisappear:] in your viewWillDisappear method.

Warren Burton
  • 17,451
  • 3
  • 53
  • 73