Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to resolve "Member access into incomplete type" error

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 ?

like image 616
Rahul Iyer Avatar asked Apr 30 '15 01:04

Rahul Iyer


1 Answers

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.

like image 139
Paulw11 Avatar answered Nov 15 '22 05:11

Paulw11