2011-03-26 36 views
0

在我的應用程序中,我希望在具有導航欄和選項卡欄的表視圖控制器中顯示iAd。我可以在我的應用程序中顯示iAd,但是當我嘗試滾動時,此iAd出現問題,問題在於iAd也在滾動單元格,因此我無法查看底部的單元格。我正在使用下面的代碼創建iAd。有人能幫我解決以下問題。滾動視圖中的iAds

#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
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: 
相關問題