Ios 加载和卸载iAd视图

Ios 加载和卸载iAd视图,ios,objective-c,iad,Ios,Objective C,Iad,点击按钮时如何加载/卸载iAd?换句话说,我希望能够在点击一个按钮时加载iAd横幅,并在点击另一个按钮时卸载它 通过下面的代码,我可以在点击loadBanner按钮时加载并显示横幅,当我点击unloadBanner按钮时问题开始,它实际上会卸载横幅,但如果我再次点击loadBanner按钮,它不会重新加载横幅,这基本上就是我想要的 移除横幅后,如何重新加载横幅 .h文件 #import <UIKit/UIKit.h> #import <iAd/iAd.h> @inter

点击按钮时如何加载/卸载iAd?换句话说,我希望能够在点击一个按钮时加载iAd横幅,并在点击另一个按钮时卸载它

通过下面的代码,我可以在点击loadBanner按钮时加载并显示横幅,当我点击unloadBanner按钮时问题开始,它实际上会卸载横幅,但如果我再次点击loadBanner按钮,它不会重新加载横幅,这基本上就是我想要的

移除横幅后,如何重新加载横幅

.h文件

#import <UIKit/UIKit.h>
#import <iAd/iAd.h>

@interface ViewController : UIViewController <ADBannerViewDelegate>
- (IBAction)loadBanner:(id)sender;
- (IBAction)unloadBanner:(id)sender;
@end

非常感谢

尝试以下方法:在loadBanner或unloadBanner方法中执行a_adBanner=nil;此外,在卸载后,您似乎没有重置_bannerisvisiblebool。添加
_bannerIsVisible=NO
to unloadBanner成功了。谢谢。我真的需要
\u adBanner.delegate=nil在横幅中?删除它在外观上没有任何区别,没有它也可以正常工作。
@interface ViewController ()
{
    BOOL _bannerIsVisible;
    ADBannerView *_adBanner;
}

- (IBAction)loadBanner:(id)sender {
    // iADBanner
    _adBanner = [[ADBannerView alloc] initWithFrame:CGRectMake(0, self.view.frame.size.height, self.view.frame.size.width, 66)];
    _adBanner.delegate = self;
}

- (IBAction)unloadBanner:(id)sender {
    [_adBanner removeFromSuperview];
    _adBanner.delegate = nil;
}

// ===================================
// ********* BANNER  ****************
// ===================================
- (void)bannerViewDidLoadAd:(ADBannerView *)banner
{
    if (!_bannerIsVisible)
    {
        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
{
    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;
    }
}