滚动视图中的iAd

时间:2011-03-26 11:46:56

标签: ios4 uitableview iad

在我的应用程序中,我想在表视图控制器中显示iAd,它同时包含导航栏和Tab栏。我能够在我的应用程序中显示iAd,但是当我尝试滚动时,这个iAd会出现问题,问题是iAd也在滚动单元格,因为我无法在底部查看单元格。我正在使用下面的代码创建iAd。可以帮助我解决以下问题。

#pragma mark -
#pragma mark === Banner View Methods ===
#pragma mark -

- (void)createBannerView {

    Class cls = NSClassFromString(@"ADBannerView");
    if (cls) {
        ADBannerView *adView = [[cls alloc] initWithFrame:CGRectZero];
        adView.requiredContentSizeIdentifiers = [NSSet setWithObjects:ADBannerContentSizeIdentifierPortrait,
                                                 ADBannerContentSizeIdentifierLandscape, nil];

        // Set the current size based on device orientation
        adView.currentContentSizeIdentifier = ADBannerContentSizeIdentifierPortrait;
        adView.delegate = self;

        adView.autoresizingMask = UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleRightMargin;

        // Set intital frame to be offscreen
        CGRect bannerFrame =adView.frame;
        bannerFrame.origin.y = self.view.frame.size.height;
        adView.frame = bannerFrame;

        self.bannerView = adView;

        [self.view addSubview:adView];
        [adView release];
    }
}

- (void)showBanner {

    CGFloat fullViewHeight = self.view.frame.size.height;
    CGRect tableFrame = self.tv.frame;
    CGRect bannerFrame = self.bannerView.frame;

    // Shrink the tableview to create space for banner
    tableFrame.size.height = fullViewHeight - bannerFrame.size.height;

    // Move banner onscreen
    bannerFrame.origin.y = fullViewHeight - bannerFrame.size.height; 

    [UIView beginAnimations:@"showBanner" context:NULL];
    self.tv.frame = tableFrame;
    self.bannerView.frame = bannerFrame;
    [UIView commitAnimations];
}

- (void)hideBanner {

    // Grow the tableview to occupy space left by banner
    CGFloat fullViewHeight = self.view.frame.size.height;
    CGRect tableFrame = self.tv.frame;
    tableFrame.size.height = fullViewHeight;

    // Move the banner view offscreen
    CGRect bannerFrame = self.bannerView.frame;
    bannerFrame.origin.y = fullViewHeight;

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

- (void)releaseBanner {

    if (self.bannerView) {
        bannerView.delegate = nil;
        self.bannerView = nil;
    }
}

- (void)changeBannerOrientation:(UIInterfaceOrientation)toOrientation {

    if (UIInterfaceOrientationIsLandscape(toOrientation)) {
        self.bannerView.currentContentSizeIdentifier = 
        ADBannerContentSizeIdentifierLandscape;
    }
    else {
        self.bannerView.currentContentSizeIdentifier = 
        ADBannerContentSizeIdentifierPortrait;
    }
}

#pragma mark -
#pragma mark === ADBannerViewDelegate Methods ===
#pragma mark -

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

    [self showBanner];
}

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

    [self hideBanner];
}

1 个答案:

答案 0 :(得分:1)

yes i got it you use addSubView which i think is wrong Add this Banner in last cell of a tableview or in a fotter of a table view if you are not use load more functionalty in you app
– tableView:viewForFooterInSection:
use that delegate method of table view UItableViewDelegate i think it helps you
– tableView:heightForFooterInSection:
add that method too to specify the height of footer of your table
add the calculate banner size code in
– tableView:heightForFooterInSection:
and add banner in – tableView:heightForFooterInSection: