I am trying to integrate iAd into a cocos2d-x project as described in: http://becomingindiedev.blogspot.com.es/2015/02/integrating-iad-in-cocos2d-x-v3x.html
AdBanner.h
#import <Foundation/Foundation.h>
#import <iAd/iAd.h>
@class RootViewController;
@interface AdBanner : NSObject<ADBannerViewDelegate>
{
UIWindow* window;
RootViewController* rootViewController;
ADBannerView* adBannerView;
bool adBannerViewIsVisible;
}
AdBanner.mm
@implementation AdBanner
-(id)init
{
if(self=[super init])
{
adBannerViewIsVisible = YES;
rootViewController =
(RootViewController*) [[[UIApplication sharedApplication] keyWindow] rootViewController];
window = [[UIApplication sharedApplication] keyWindow];
[self createAdBannerView];
}
return self;
}
-(void)layoutAnimated:(BOOL)animated
{
CGRect bannerFrame = adBannerView.frame;
//Has the banner an advestiment?
if ( adBannerView.bannerLoaded && adBannerViewIsVisible )
{
NSLog(@"Banner has advertisement");
bannerFrame.origin.y = window.bounds.size.height - bannerFrame.size.height;
} else
{
NSLog( @"Banner has NO advertisement" );
//if no advertisement loaded, move it offscreen
bannerFrame.origin.y = window.bounds.size.height;
}
[UIView animateWithDuration:animated ? 0.25 : 0.0 animations:^{
[rootViewController.view layoutIfNeeded]; //Member access into incomplete type "RootViewController"
adBannerView.frame = bannerFrame;
}];
}
@end
The line at the bottom in AdBanner.mm gives the error:
[rootViewController.view layoutIfNeeded]; //Member access into incomplete type "RootViewController"
How do I resolve this ?
You have declared RootViewController
as a forward class declaration in your .h file using the @Class
directive, but you haven't imported RootViewController.h in your ADBanner.mm file.
This means that the compiler knows that there is some class RootViewController
but doesn't know anything more about it - its superclass, methods or properties. As such it can't confirm that it actually has a method layoutIfNeeded
.
Adding #import "RootViewController.h"
to the top of ADBanner.mm will give the compiler the information it needs and resolve the error.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With