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



我有一个带有两个视图控制器的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;
    }
}

我知道为什么,只是不知道怎么修。有人能帮我吗?

您在viewDidAppear中创建了一个ADBannerView的实例,并将其分配给adView。您似乎不会对此执行任何操作,更相关的是,也不会在viewWillDisappear中丢弃它,因此每次您弹回此视图控制器时,当您循环使用viewDidAppear时,上一个实例都会孤立。

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

相关内容

  • 没有找到相关文章

最新更新