我正试图在我的应用程序底部插入一个iad横幅,但在完成以下教程后仍然遇到错误。 代码如下。
@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];
}
我一直收到以下错误 *由于未捕获的异常'NSInvalidUnarchiveOperationException'而终止应用程序,原因:'无法实例化名为ADBannerView的类' * 首先抛出调用堆栈:
答案 0 :(得分:20)
请确保您已添加&#34; iAd.framework&#34; ...
要执行此操作,请转到&#34;应用程序。目标&#34;,&#34;一般&#34;并向下滚动,直到您看到&#34;链接的框架和库&#34;。命中&#34; +&#34;并选择iAd框架。请参阅下面的屏幕截图...
答案 1 :(得分:0)
您尚未创建AdBannerview的对象..
首先,为横幅视图创建对象并为其设置委托。
-(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];
}
}