How to resolve "Member access to incomplete type" error

I am trying to integrate iAd into a cocos2d-x project as described in: http://becomingindieie.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 below in AdBanner.mm gives an error:

  [rootViewController.view layoutIfNeeded]; //Member access into incomplete type "RootViewController" 

How to resolve this?

+5
source share
1 answer

You declared RootViewController as a direct class declaration in the .h file using the @Class directive, but you did not import RootViewController.h into the ADBanner.mm file.

This means that the compiler knows that there is some class RootViewController , but no longer knows about it - its superclass, methods or properties. Thus, it cannot confirm that it actually has a layoutIfNeeded method.

Adding #import "RootViewController.h" to the beginning of ADBanner.mm will provide the compiler with the information it needs and fix the error.

+9
source

All Articles