I would like to send the message from HelloWorldLayer, and receive it in ScoreLayer, in order to update the label. The CCLOG(@"///addNewScore"); works fine, but then updateScore, in ScoreLayer, does not receive the call, would you know why? Here’s my code : (edit: i tried with “retain” in @property, but nothing changes) :
@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
Thanks a lot
I suspect that the ScoreLayer is being released before your call. I’m not too familiar with
assign, I have only written ARC Objective-C; but I think it is roughly the same as weak (as it should be for delegates). This means that in order for that pointer to be valid, someone else in the application needs to “own” the ScoreLayer.Now, that being said, I’ve only assumed that you are properly connecting the two objects in the first place. There isn’t code posted which shows that, but this matter of a possibly-released ScoreLayer is important enough to keep in mind either way.