2015-04-30 35 views
5

Tôi cố gắng để tích hợp iAd vào một dự án cocos2d-x như mô tả trong: http://becomingindiedev.blogspot.com.es/2015/02/integrating-iad-in-cocos2d-x-v3x.htmlLàm thế nào để giải quyết "truy cập thành viên vào loại không đầy đủ" lỗi

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 

dòng ở dưới cùng trong AdBanner.mm cung cấp cho các lỗi:

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

Làm cách nào để giải quyết vấn đề này?

+0

'rootViewController' trông giống như một con trỏ, thử' -> '? – user3528438

+0

Đây là mã khách quan-C++. –

+0

Nó đã được gắn thẻ C++ trước vsoftco đã chỉnh sửa nó ..... – user3528438

Trả lời

9

Bạn đã khai báo RootViewController làm khai báo lớp chuyển tiếp trong tệp .h bằng chỉ thị @Class, nhưng bạn chưa nhập RootViewController.h vào tệp ADBanner.mm của mình.

Điều này có nghĩa là trình biên dịch biết rằng có một số lớp RootViewController nhưng không biết gì thêm về nó - siêu lớp, phương thức hoặc thuộc tính của nó. Như vậy nó không thể xác nhận rằng nó thực sự có một phương thức layoutIfNeeded.

Thêm #import "RootViewController.h" vào đầu ADBanner.mm sẽ cung cấp cho trình biên dịch thông tin cần thiết và giải quyết lỗi.

Các vấn đề liên quan