我的游戏开始屏幕上有一个按钮,当用户点击该按钮时,它将重定向到下一页,我在此按钮单击事件中调用通知,其代码是
- (void)switchsounds
{
CCLOG(@"hiii");
[[NSNotificationCenter defaultCenter] postNotificationName:@"reloadvieweyes" object:nil];
CCTransitionJumpZoom *transition = [CCTransitionJumpZoom transitionWithDuration:1.0 scene:[HelloWorldLayer scene]];
// Tell the director to run the transition
[[CCDirector sharedDirector] replaceScene:transition];
}
上面的代码是按钮点击函数
在 init statmnet 的下一页上,我放置此代码来获取按钮事件的功能
-(id) init
{
if( (self=[super init])) {
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(viewreloadedeyes) name:@"reloadvieweyes" object:nil];
}
return self;
}
-(void)viewreloadedeyes
{
CCLOG(@"hiii");
}
我没有在按钮单击事件中获得 cclog 以及下一页中的功能。但是页面重定向是通过按钮 lcick 完成的。我的代码有什么问题。如何从一个页面到另一个页面获取 nsnofication单击按钮。
提前致谢。
最佳答案
通知选择器 require the NSNotification* parameter 。将您的代码更改为:
-(id) init
{
if( (self=[super init])) {
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(viewreloadedeyes:)
name:@"reloadvieweyes"
object:nil];
}
return self;
}
-(void)viewreloadedeyes:(NSNotification*)notification
{
CCLOG(@"hiii");
}
关于iphone - Cocos2d iPhone 中的 NSNotification,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12067637/