目标c - Admob使用Storyboard - UIView可能不响应viewDidLoad



我已经搜索和更改代码2天了。我用的是xcode 4.5和storyboards。我让admob在我的主视图上工作,但我已经添加了50多个其他视图,并且得到了一些警告,广告不会显示。

//  ViewMain2.h
#import <UIKit/UIKit.h>
#import "GADBannerView.h"
@class GADBannerView, GADRequest;
@interface ViewMain2 : UIView 
<GADBannerViewDelegate> {
    GADBannerView *adBanner_;
}
@property (nonatomic, retain) GADBannerView *adBanner;
- (GADRequest *)createRequest;
- (UIView *)view;
@end
//////////  ViewMain2.m
#import "ViewMain2.h"
#import "GADBannerView.h"
#import "GADRequest.h"
@implementation ViewMain2
@synthesize adBanner = adBanner_;
- (UIView *)view {
    return (UIView *)self.view;
}
- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
    }
    return self;
}
#pragma mark init/dealloc
// Implement viewDidLoad to do additional setup after loading the view,
// typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];
    // Initialize the banner at the bottom of the screen.
    CGPoint origin = CGPointMake(0.0,
                                 self.view.frame.size.height -
                                 CGSizeFromGADAdSize(kGADAdSizeBanner).height);
    // Use predefined GADAdSize constants to define the GADBannerView.
    self.adBanner = [[[GADBannerView alloc] initWithAdSize:kGADAdSizeBanner
                                                    origin:origin]
                     autorelease];
    // Note: Edit SampleConstants.h to provide a definition for kSampleAdUnitID
    // before compiling.
    self.adBanner.adUnitID = @"a1512d23a796691";
    self.adBanner.delegate = self;
    [self.adBanner setRootViewController:self];
    [self.view addSubview:self.adBanner];
    self.adBanner.center =
    CGPointMake(self.window.center.x, self.adBanner.center.y);
    [self.adBanner loadRequest:[self createRequest]];
}
- (void)dealloc {
    adBanner_.delegate = nil;
    [adBanner_ release];
    [super dealloc];
}
- (NSUInteger)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskPortrait;
}
#pragma mark GADRequest generation
// Here we're creating a simple GADRequest and whitelisting the application
// for test ads. You should request test ads during development to avoid
// generating invalid impressions and clicks.
- (GADRequest *)createRequest {
    GADRequest *request = [GADRequest request];
    // Make the request for a test ad. Put in an identifier for the simulator as
    // well as any devices you want to receive test ads.
    request.testDevices =
    [NSArray arrayWithObjects:
     // TODO: Add your device/simulator test identifiers here. They are
     // printed to the console when the app is launched.
     nil];
    return request;
}
#pragma mark GADBannerViewDelegate impl
// We've received an ad successfully.
- (void)adViewDidReceiveAd:(GADBannerView *)adView {
    NSLog(@"Received ad successfully");
}
- (void)adView:(GADBannerView *)view
didFailToReceiveAdWithError:(GADRequestError *)error {
    NSLog(@"Failed to receive ad with error: %@", [error localizedFailureReason]);
}
@end

我得到一个警告"UIView可能不响应viewDidLoad"的行-> [super viewDidLoad];

我也得到一个警告"不兼容的指针类型发送ViewMain2到类型的参数UIViewController"行-> [self。

adBanner setRootViewController:自我);

我已经尝试了很多教程和搜索,但与所有的视图在故事板名为UIView,我挣扎。谢谢你的帮助!

您声明您的类是UIView的子类:

@interface ViewMain2 : UIView 

然而,您正试图将其用作UIViewController。决定哪一个你想要-如果一个视图控制器,然后改变超类UIViewController,如果一个视图,然后不要试图使用它作为一个视图控制器

最新更新