2012-07-22 91 views
-1

因此,基本上我的接口中有一個協議,我需要包含在我的實現中,因爲我得到一個不完整的錯誤,因此無法繼續。Cocos2d,需要在我的實現文件中包含協議

。 .h文件

@interface waveLayer1 : CCLayer <GameKitHelperProtocol> 
{ 
    ... 
} 

.m文件

@implementation waveLayer1 

GameKitHelper.h文件

#import "cocos2d.h" 
#import <GameKit/GameKit.h> 
@protocol GameKitHelperProtocol 
-(void) onLocalPlayerAuthenticationChanged; 
-(void) onFriendListReceived: (NSArray*)friends; 
-(void) onPlayerInfoReceived:(NSArray*)players; 
@end 

@interface GameKitHelper : NSObject { 
    id<GameKitHelperProtocol> delegate; bool isGameCenterAvailable; NSError* lastError; 
} 
@property (nonatomic, retain) id<GameKitHelperProtocol> delegate; 
@property (nonatomic, readonly) bool isGameCenterAvailable; @property (nonatomic, readonly) NSError* lastError; 

+(GameKitHelper*) sharedGameKitHelper; 
// Player authentication, info 
-(void) authenticateLocalPlayer; 
-(void) getLocalPlayerFriends; 
-(void) getPlayerInfo:(NSArray*)players; 
@end 

的錯誤是我有更多的文件,我可以顯示 「未實現的協議方法」,但節省空間我決定看看你是否可以幫助我解決這個問題只用這些代碼

回答

0

實現你的waveLayer1類這3種方法..

-(void) onLocalPlayerAuthenticationChanged; 
-(void) onFriendListReceived:(NSArray*)friends; 
-(void) onPlayerInfoReceived:(NSArray*)players; 
1
@interface waveLayer1 : CCLayer <GameKitHelperProtocol> 

這就是說「wavelayer1」實現了協議「GameKitHelperProtocol」。

Method in protocol not implemented 

表示在協議中聲明的方法尚未實現。很有可能你忘了實現其中一個「GameKitHelperProtocol」方法,這會使你的類不實現該協議,這違反了你所做的聲明,導致編譯器輸出一個錯誤。

0

當您聲明一個類採用協議時,您必須爲該協議中定義的所有必需方法編寫一個實現。所以在這種情況下,您需要添加在GameKitHelperProtocol中定義的方法實現。