Could not instantiate class named ADBannerView

泪湿孤枕 提交于 2019-12-08 21:41:22

问题


i am trying to inset an iad banner at the bottom of my app but keep getting errors after following tutorials. code as follows.

@interface DMKHomeViewController (UIViewcontroller ) <ADBannerViewDelegate>{

}
@end

@implementation DMKHomeViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
    // Custom initialization
}
return self;
}

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

[UIView beginAnimations:nil context:NULL];

[UIView setAnimationDuration:1];

[banner setAlpha:1];

[UIView commitAnimations];

}



- (void)bannerView:(ADBannerView *)

banner didFailToReceiveAdWithError:(NSError *)error

{

[UIView beginAnimations:nil context:NULL];

[UIView setAnimationDuration:1];

[banner setAlpha:0];

[UIView commitAnimations];

}

i keep getting the following error * Terminating app due to uncaught exception 'NSInvalidUnarchiveOperationException', reason: 'Could not instantiate class named ADBannerView' * First throw call stack:


回答1:


Please make sure that you have added the "iAd.framework"...

To do this go to the "App. Target", "General" and scroll down until you see "Linked Frameworks and Libraries". Hit "+" and select the iAd framework. See screen captures below...




回答2:


You have not created object of AdBannerview..

First, create object for banner view and set delegate for it.

-(void)ViewDidLoad
{
   [self createBannerView];
}
- (void)createBannerView {

  Class cls = NSClassFromString(@"ADBannerView");
  if (cls) {
    ADBannerView *adView = [[cls alloc] initWithFrame:CGRectZero];


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

    adView.autoresizingMask = UIViewAutoresizingFlexibleTopMargin |
                              UIViewAutoresizingFlexibleRightMargin;

    // Set initial 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];
  }
}


来源:https://stackoverflow.com/questions/24081669/could-not-instantiate-class-named-adbannerview

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