我想從HelloWorldLayer發送消息,並在ScoreLayer中接收消息,以更新標籤。該CCLOG(@"///addNewScore");
工作正常,但然後updateScore
,在ScoreLayer,沒有收到電話,你知道爲什麼嗎?這裏是我的代碼:(編輯:我試圖用@property「保留」,但沒有任何變化):爲什麼我的自定義委託方法沒有收到呼叫?
@interface HelloWorldLayer : CCLayer
{
//...
id<ScoreDelegate>delegate;
}
@property (nonatomic,retain) id <ScoreDelegate> delegate;
@implementation HelloWorldLayer
@synthesize delegate;
//...
-(void)addNewScore:(int)num{
CCLOG(@"///addNewScore");//works fine
[delegate updateScore:num];
}
#import <Foundation/Foundation.h>
@protocol ScoreDelegate
-(void)updateScore:(int)num;
@end
@interface ScoreLayer : CCLayer <ScoreDelegate>{
//...
}
-(void)updateScore:(int)num{
CCLOG(@"hello");//DOES NOT WORK
}
@end
非常感謝
你沒有顯示你設置'HelloWorldLayer'的'delegate'屬性的地方。我以爲你在做這個地方? – mttrb
@mttrb:對不起mttrb你是什麼意思?關於委託的所有代碼都在上面,我錯過了什麼嗎? – Paul
澄清:我們正在尋找的代碼將如下所示:'anHelloWorldLayer.delegate = aScoreLayer',以及上下文,例如代碼中出現的位置。 –