警告:当前存在超过10个ADBannerView或ADInterstitialView实例

时间:2015-02-25 18:59:31

标签: objective-c ios8.1 adbannerview

我有一个带2个视图控制器的iPad应用程序;第一个用于UI,第二个用于显示UIWebView帮助的视图。当我在视图控制器之间来回转换10次时,我在完全上面的标题中得到消息,第10次返回到第一个VC。

这是我在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;
    }
}

我知道为什么,只是不知道如何解决它。有人可以帮帮我吗?

1 个答案:

答案 0 :(得分:0)

您在ADBannerView中创建viewDidAppear的实例,并将其分配给adView您似乎没有对此做任何事情,更不相关请勿在{{1​​}中丢弃它所以每次弹回这个视图控制器时,当你循环viewWillDisappear时,前一个实例就会孤立。

另外一个问题是您没有在viewDidAppear方法中调用[super viewWillDisappear:]