2013-03-02 44 views
0

我一直在搜索和更改代碼2天。我正在使用xcode 4.5和故事板。我讓admob參與了我的主要觀點,但我增加了50多個其他視圖,並且發出了一些警告,並且廣告不會顯示出來。Admob使用Storyboard - UIView可能不會響應viewDidLoad

// 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」 - > [超級viewDidLoad中]

我也收到警告「不兼容的指針類型發送ViewMain2參數類型UIViewController」在行 - > [self.adBanner setRootViewController:self];

我已經嘗試了很多教程和搜索,但所有的故事板名爲UIView的意見,我掙扎。謝謝你的幫助!

回答

0

你申報你的類是UIView一個子類:

@interface ViewMain2 : UIView 

但是,你要使用它作爲一個UIViewController。決定你想要哪一個 - 如果一個視圖控制器,然後改變超類爲UIViewController,如果一個視圖,那麼不要嘗試使用它作爲視圖控制器。

相關問題