使用如下:
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
网友评论