我隐藏了我的AdBannerView但仍然得到警告横幅视图(0x9c75550)有一个广告

时间:2011-10-31 23:13:38

标签: ios modal-dialog adbannerview

我刚刚在我的应用中添加了ADBannerview。我在UIApplicationDelegate中创建了AdBannerView,以便只有一个实例,并在不同的viewController中共享它

除了收到警告信息外,一切正常:ADBannerView:警告横幅视图(0x9c75550)有一个广告,但可能会被遮挡。此消息仅在每个横幅视图中打印一次。

当我在当前显示ADBannerview的视图顶部打开模态视图(使用presentModalViewController)时。在打开模态视图之前,我使用以下代码隐藏ADBannerview:

- (void)viewWillDisappear:(BOOL)animated
{
    ADBannerView *bannerView = [ (ScoreBoardAppDelegate*)[[UIApplication sharedApplication] delegate] adBanner];
    [self hideBanner:bannerView];
    [super viewWillDisappear:animated];
}

- (void)hideBanner:(ADBannerView*) adBanner {
    NSLog(@"%s called", __FUNCTION__);

    // Grow the tableview to occupy space left by banner, it's the size of the parent view
    CGFloat fullViewHeight = self.tbView.frame.size.height;
    CGRect tableFrame = self.tv.frame;
    tableFrame.size.height = fullViewHeight;

    // Move the banner view offscreen
    CGRect bannerFrame = adBanner.frame;

    CGRect screenBounds = [[UIScreen mainScreen] bounds];
    bannerFrame.origin = CGPointMake(CGRectGetMinX(screenBounds), CGRectGetMaxY(screenBounds));

    self.tv.frame = tableFrame;
    adBanner.frame = bannerFrame;
}

我不明白该怎么做才能没有这条警告信息。在显示模态视图之前,似乎ADBannerView已成功隐藏(屏幕外)。

我可能错过了一些东西,但我看不到它。 谢谢你的帮助,

塞巴斯蒂安。

1 个答案:

答案 0 :(得分:1)

塞巴斯蒂安,我希望你已经离开了这个问题,因为这个问题已经持续了好几个月了。我最近添加了iAd支持,发现这个警告也非常烦人。共享广告横幅的一个细微之处在于,如果要在初始视图控制器中显示它,则必须在该视图控制器中进行大部分设置,而不是在应用程序委托中进行。

这是我的初始视图控制器中的viewWillAppear:方法:

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    if (!SharedAdBannerView) {
        // in my app, the ad banner is the bottom-most thing on screen
        CGRect startingFrame = CGRectMake(0.0, self.view.frame.origin.y + self.view.frame.size.height, 320.0, 50.0);
        adBanner = [[ADBannerView alloc] initWithFrame:startingFrame];

        // Set the autoresizing mask so that the banner is pinned to the bottom
        adBanner.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleTopMargin;

        // Since we support all orientations, support portrait and landscape content sizes.
        // If you only supported landscape or portrait, you could remove the other from this set
        adBanner.requiredContentSizeIdentifiers = [NSSet setWithObjects:ADBannerContentSizeIdentifierPortrait, nil];
        adBanner.currentContentSizeIdentifier = ADBannerContentSizeIdentifierPortrait;

        adBanner.delegate = self;
        [self.view addSubview:adBanner];
        SharedAdBannerView = adBanner; 
    } else {
        adBanner = SharedAdBannerView;
}

SharedAdBannerView是TN2286中定义的宏,它使用在app delegate上定义的实例变量(这是在显示iAd的所有视图之间共享的方式)。我还决定在屏幕上为广告横幅设置动画,然后将其从视图层次结构中移除,因为一个场景正在转移到另一个场景。我阅读文档时说,只要广告横幅是视图层次结构的一部分,您就会得到该消息 - 换句话说,隐藏横幅视图不是阻止警告消息的方法。或者换句话说,如果它足以隐藏广告横幅,它对我来说不起作用,它对故障排除没有帮助。当我遇到TN2239时,我学到了很多东西,它在gdb中提供了这个技巧:

 po [[self view] recursiveDescription];

您必须根据放置断点的位置调整发送recursiveDescription消息的对象,但可能[自我查看]没问题。