美文网首页
通知移除提示没有注册崩溃NSNotificationCenter

通知移除提示没有注册崩溃NSNotificationCenter

作者: 上山砍柴 | 来源:发表于2019-09-25 13:58 被阅读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

    相关文章

      网友评论

          本文标题:通知移除提示没有注册崩溃NSNotificationCenter

          本文链接:https://www.haomeiwen.com/subject/chdoectx.html