iphone - Cocos2d iPhone 中的 NSNotification

标签 iphone ios cocos2d-iphone

我的游戏开始屏幕上有一个按钮,当用户点击该按钮时,它将重定向到下一页,我在此按钮单击事件中调用通知,其代码是

- (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/

相关文章:

ios - 应用程序启动后加载不同的 View Controller

iphone - CGContextClearRect 带圆圈

ios - 自 Xcode 8 以来的 Layout Interface Builder 约束问题

objective-c - NSArray 反向索引排序

iphone - 比较 NSDates

iphone - 是否可以通过编程方式调暗 iPhone 相机闪光灯的光线?

objective-c - 正确使用FMDB/内存

cocos2d-iphone - EXC_??? (11)(代码=0,子代码=0x0

ios - 在CCSprite上设置颜色叠加 - Spritebuilder/Cocos2d

objective-c - Iphone 2d 游戏 - 应用重力,弹跳问题