如何解决"会员访问不完整类型"错误

时间:2015-04-30 01:58:15

标签: ios objective-c iad objective-c++

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

AdBanner.h

sshd

AdBanner.mm

 #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

如何解决此问题?

1 个答案:

答案 0 :(得分:9)

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

这意味着编译器知道有一些类RootViewController但是对它没有更多了解 - 它的超类,方法或属性。因此,它无法确认它实际上有方法layoutIfNeeded

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