【发布时间】:2014-09-11 10:52:15
【问题描述】:
我有由 ViewController 控制的 SKScene。在这个 SKScene 中,我有一个带有一些程序的棋盘对象(从 NSObject 派生)。我需要从其中一个程序(游戏板程序)中发布通知。在 ViewController 我有一个观察者:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(rowBangEmitAtPosition:) name:@"rowBangN" object:nil];
在游戏板的程序里面我有:
[[NSNotificationCenter defaultCenter] postNotificationName:@"rowBangN" object:self userInfo:@{@"position":point}];
对象是 SKScene 的一部分(作为变量)。但是这个通知永远不会被触发。谁能帮帮我。
【问题讨论】:
-
发布您的 rowBangEmitAtPosition: 实现以及调用方法的顺序。含义:确保您在发布通知之前注册了观察者。
-
我在 -(void)viewDidLoad 期间注册了观察者,并在 -(void)viewWillLayoutSubviews 期间初始化场景和对象,所以我认为没问题。
-
您是否尝试过使用 NSLog 或断点来验证该方法没有被调用?
-
是的,断点和NSLog都有,但是没有触发。
标签: sprite-kit nsnotifications