如何解决“成员访问不完整类型”错误

时间:2022-09-07 08:34:35

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

我正在尝试将iAd集成到cocos2d-x项目中,如下所述:http://becomingindiedev.blogspot.com.es/2015/02/integrating-iad-in-cocos2d-x-v3x.html

AdBanner.h

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

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:

AdBanner.mm底部的行给出错误:

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

How do I resolve this ?

我该如何解决这个问题?

1 个解决方案

#1


9  

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.

您已使用@Class指令将RootViewController声明为.h文件中的转发类声明,但您尚未在ADBanner.mm文件中导入RootViewController.h。

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.

这意味着编译器知道有一些类RootViewController但不知道更多关于它的东西 - 它的超类,方法或属性。因此,它无法确认它实际上有一个方法layoutIfNeeded。

Adding #import "RootViewController.h" to the top of ADBanner.mm will give the compiler the information it needs and resolve the error.

将#import“RootViewController.h”添加到ADBanner.mm的顶部将为编译器提供所需的信息并解决错误。

#1


9  

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.

您已使用@Class指令将RootViewController声明为.h文件中的转发类声明,但您尚未在ADBanner.mm文件中导入RootViewController.h。

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.

这意味着编译器知道有一些类RootViewController但不知道更多关于它的东西 - 它的超类,方法或属性。因此,它无法确认它实际上有一个方法layoutIfNeeded。

Adding #import "RootViewController.h" to the top of ADBanner.mm will give the compiler the information it needs and resolve the error.

将#import“RootViewController.h”添加到ADBanner.mm的顶部将为编译器提供所需的信息并解决错误。