iAd Banner View Delegate Not Calling Methods

僤鯓⒐⒋嵵緔 提交于 2019-12-11 10:44:22

问题


I have an iAd banner view, with all my contracts up and running, and I've implemented the ADBannerView delegate. The banner should disappear with no internet connection, but it just shows a white box where the content should be. I know I have all the code right, I've seen a million tutorials on this. So I ran some tests and found that the banner view wasn't even calling the two methods for the delegate! Here is the code.

In the .h file:

#import <iAd/iAd.h>

@interface DetailViewController : ADBannerViewDelegate>
{
    ADBannerView *aBanner;
    BOOL bannerIsVisible;
}

@property (nonatomic, retain) IBOutlet ADBannerView *aBanner;
@property (nonatomic, assign) BOOL bannerIsVisible;

@end

in the .m file:

@implementation DetailViewController

@synthesize aBanner,bannerIsVisible;

//Show banner if can load ad.
-(void)bannerViewDidLoadAd:(ADBannerView *)banner
      { 
         if (!self.bannerIsVisible) { 
            [UIView beginAnimations:@"animateAdBannerOn" context:NULL]; banner.frame = CGRectOffset(banner.frame, 0, -banner.frame.size.height); 
            [UIView commitAnimations]; self.bannerIsVisible = YES; }
      }

    //Hide banner if can't load ad.
    -(void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error
    { 
        if (self.bannerIsVisible) { 
            [UIView beginAnimations:@"animateAdBannerOff" context:NULL]; banner.frame = CGRectOffset(banner.frame, 0, banner.frame.size.height);           
            [UIView commitAnimations]; self.bannerIsVisible = NO; }
    }

回答1:


You have to set the banner delegate to files owner. I had the same issue and after beating my head against the wall it was that simple.




回答2:


Use the code shown below to declare your own delegate

-(void)viewDidLoad {
  aBanner.delegate = self;
}


来源:https://stackoverflow.com/questions/8963972/iad-banner-view-delegate-not-calling-methods

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!