通知移除提示没有注册崩溃NSNotificationCenter
2019-09-25 本文已影响0人
上山砍柴
使用如下:
NSNotificationCenter.defaultCenter().addObserver(self, selector:"selector name", name: "observer name", object:nil)
NSNotificationCenter.defaultCenter().removeObserver(self, forKeyPath: <some string>)
错误:
Terminating app due to uncaught exception 'NSRangeException', reason: 'Cannot remove an observer "class" for the key path "some string" from NSNotificationCenter because it is not registered as an observer.
方案:
I think you should use code
NSNotificationCenter.defaultCenter().removeObserver(self)
Explain: You have mistake here: You are using NSNotification & NSNotificationCenter so you have to using this code above to remove observe. you have use code for KVO to remove observer so it will wrong.
More detail you can read at here. Key-Value-Observing