我对 NSNotificationCenter 有疑问。现在它崩溃了,但几天前,当我添加通知时,它工作正常。在这期间,我添加了一些与此无关的代码。
我有大约 10x10 的瓷砖。每个图块在创建后立即将自己添加为观察者:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(playerJumped) name:@"TestNot" object:nil];
在我的播放器类中,每次跳转结束时,我都会使用以下代码发布通知:
if (self.postNotifications == YES) {
//Also post the notification for all the Tiles.
[[NSNotificationCenter defaultCenter] postNotificationName:@"TestNot" object:self];
}
如果我在图块中使用 NSLog(),我可以看到大约 3 或 4 个图块收到通知。之后,应用程序因 EXC_BAD_ACCESS 而崩溃。它说objc_msgSend() selector name: playerJumped
。但我不明白为什么。我看到它适用于第一个而不是崩溃。我的错误是什么?你能帮我么!桑德罗
编辑:有问题吗,因为大约 100 个对象收到了通知?