ios - NSNotification - 观察者不匹配

标签 ios objective-c notifications nsnotificationcenter

我使用 NSNotificationCenter:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(playNow:) name:@"PlayNow" object:nil];

和发布:

[[NSNotificationCenter defaultCenter] postNotificationName:@"PlayNow" object:nil userInfo:noteInfoDictionary];

其中 self 是 @interface MyPlayer : NSObject 的实例

当我调用它时,它在大多数情况下工作得很好,但是当我解除分配并分配回 MyPlayer 实例时,我收到此错误:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIView playNow:]: unrecognized selector sent to instance 0x8929150'

我怎么可能从 UIView 收到错误?

最佳答案

你必须在 dealloc 中移除观察者:

[[NSNotificationCenter defaultCenter] removeObserver:self]

关于ios - NSNotification - 观察者不匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16674222/

相关文章:

ios - 以编程方式创建 TableView 时未显示

ios - PDFKit : How to move current page in PDFView to a specific offset

iphone - NSFetchedResultsController 在彼此之上创建重复的单元格

ios - 获取整数的相同实例

ios - 比较 iOS7.1 上损坏的 JSON 数据

java - 检测何时使用 java 访问/读取文件

ios - 实际上发送带有 iOS 通知的图像文件

iphone - Cocos2d - 自上而下的旋转相机 View

ios - 使用各种结构调用 func

ruby-on-rails - 如何发送通知用户收到私有(private)消息