我正试图在我的应用程序中获取横幅,但由于我添加了横幅,应用程序无法启动。
我得到一个错误说:
由于未捕获异常"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;
}
}
你认为哪里不对?
您必须将iAd.framework添加到项目中。
取此代码:
#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