10

我试图在我的应用程序中获得横幅,但由于我添加了横幅,应用程序将无法启动。

我收到一条错误消息:

由于未捕获的异常“NSInvalidUnarchiveOperationException”而终止应用程序,原因:“无法实例化名为 ADBannerView 的类”

.h 文件中的代码:

#import <iAd/iAd.h>

@interface FirstViewController : UIViewController <ADBannerViewDelegate>
{
    ADBannerView *banner;  
}
@property (nonatomic,assign) BOOL bannerIsVisible;
@property (nonatomic,retain) IBOutlet ADBannerView *banner;

.m 文件中的代码:

@synthesize banner, bannerIsVisible;

-(void)bannerViewDidLoad: (ADBannerView *)abanner
{
     if(!self.bannerIsVisible)
     {
         [UIView beginAnimations:@"animatedAdBannerOn" context:NULL];
         banner.frame=CGRectOffset(banner.frame, 0.0, 50.0);
         [UIView commitAnimations];
         self.bannerIsVisible=YES;
     }
}
-(void)bannerView:(ADBannerView *)aBanner
{
     if(!self.bannerIsVisible)
     {
         [UIView beginAnimations:@"animatedAdBannerOff" context:NULL];
          banner.frame=CGRectOffset(banner.frame, 0.0, -320.0);
         [UIView commitAnimations];
         self.bannerIsVisible=NO;
     }
}

你觉得哪里不对?

4

2 回答 2

19

您必须将 iAd.framework 添加到您的项目中。

于 2012-12-01T02:01:52.310 回答
1

拿这个代码:

#import <iAd/iAd.h>

@interface ViewController : UIViewController <ADBannerViewDelegate> {
}
@end

.m 文件:

@implementation ViewController

-(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];
}
@end
于 2012-10-19T23:18:44.953 回答